Boolean Expressions
Đã giới thiệu| English | Ý nghĩa |
|---|---|
| Boolean expression/ˈbuːlɪən ekˈspreʃn/ | Biểu thức logic |
| evaluates/ɪˈvæljuːeɪts/ | đánh giá |
| Relational operators/rɪˈleɪʃənl ˈɒpəreɪtəz/ | toán tử quan hệ |
| logical operators/ˈlɒdʒɪkl ˈɒpəreɪtəz/ | toán tử logic |
| condition/kənˈdɪʃn/ | điều kiện |
| program flow/ˈprəʊɡræm fləʊ/ | luồng chương trình |
True-or-false questions
- Programs make decisions by asking true-or-false questions.
- A Boolean expression 布尔表达式 is any expression that evaluates 求值 to true or false.
- The answer is always one of exactly two values.
- These questions are how a program decides what to do next.
A Boolean expression always evaluates to:
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Exactly one of two values: true or false.
The expression 5 > 3 evaluates to false.
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
False. 5 is greater than 3, so 5 > 3 evaluates to true.
Relational operators
- Relational operators 关系运算符 compare two values.
- They are: equal to, not equal to, greater than $>$, less than $<$, $\ge$, and $\le$.
- Each comparison gives true or false: $5 > 3$ is true, and $4 = 7$ is false.
- One relational operator gives one simple Boolean answer.

The three families of operators: arithmetic, relational, and logical
True or false?
Relational operators compare values; logical operators combine them. AND needs both true; OR needs at least one; NOT reverses.
true AND false evaluates to:
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
AND is true only when both parts are true.
true OR false evaluates to:
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
OR is true when at least one part is true.
The logical operator that reverses a value (NOT true is false) is ______.
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
NOT flips true to false and false to true.
Logical operators
- Combine conditions with logical operators 逻辑运算符:
- AND is true only when both parts are true.
- OR is true when at least one part is true.
- NOT reverses a value: NOT true is false.
Pass needs score ≥ 50 AND attendance > 80. With score 60, attendance 75, the student:
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
60 ≥ 50 is true, 75 > 80 is false; true AND false is false.
Conditions control the flow
- A Boolean expression is often used as a condition 条件 that controls program flow 程序流.
- Evaluate each part in turn, then combine, to predict the result.
Pass rule. A student passes if score $\ge 50$ AND attendance $> 80$. With score 60, attendance 75: first part $60 \ge 50$ is true; second part $75 > 80$ is false; true AND false is false — no pass. If attendance were 90, both are true, so the whole is true.
A Boolean expression evaluates to true or false. Relational operators ($>$, $<$, $=$, $\ne$, $\ge$, $\le$) compare two values; logical operators combine conditions — AND (both), OR (at least one), NOT (reverse). Used as a condition, a Boolean expression controls program flow.