Boolean Expressions
Introduced| English | Meaning |
|---|---|
| Boolean expression/ˈbuːlɪən ekˈspreʃn/ | An expression whose value is true or false. |
| evaluates/ɪˈvæljuːeɪts/ | evaluates |
| Relational operators/rɪˈleɪʃənl ˈɒpəreɪtəz/ | Operators that compare values, such as less than or greater than, and produce a Boolean result. |
| logical operators/ˈlɒdʒɪkl ˈɒpəreɪtəz/ | logical operators |
| condition/kənˈdɪʃn/ | A requirement or circumstance that affects what happens or whether something is true. |
| program flow/ˈprəʊɡræm fləʊ/ | program flow |
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:
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Exactly one of two values: true or false.
The expression 5 > 3 evaluates to false.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
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:
Difficulty 1/5 · 100 coins + a small bonus on first completion today
AND is true only when both parts are true.
true OR false evaluates to:
Difficulty 1/5 · 100 coins + a small bonus on first completion today
OR is true when at least one part is true.
The logical operator that reverses a value (NOT true is false) is ______.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
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:
Difficulty 1/5 · 100 coins + a small bonus on first completion today
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.