Appearance
3.5 Boolean Expressions 布尔表达式
The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.
- 程序中语句的排序和组合方式决定了计算结果。程序结合迭代和选择结构来表示重复并做出决策来处理各种输入值。
核心要点 Core Points
A Boolean value is either true or false.
- 布尔值要么是真要么是假。
The exam reference sheet provides the following relational operators: =, ≠, >, <, ≥, and ≤.
- 考试参考表提供以下关系运算符:=、≠、>、<、≥和≤。
These relational operators are used to test the relationship between two variables, expressions, or values. A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to false.
- 这些关系运算符用于测试两个变量、表达式或值之间的关系。使用关系运算符的比较计算为布尔值。例如,如果a和b相等,a = b计算为真;否则,它计算为假。
The exam reference sheet provides the logical operators NOT, AND, and OR, which evaluate to a Boolean value.
- 考试参考表提供逻辑运算符NOT、AND和OR,它们计算为布尔值。
The
NOToperator evaluates totrueif theconditionisfalse; otherwise it evaluates tofalse. (Example:NOT (condition))- 如果
condition是false,NOT运算符计算为true;否则它计算为false。(示例:NOT (condition))
- 如果
The
ANDoperator evaluates totrueif bothcondition1andcondition2aretrue; otherwise it evaluates tofalse. (Example:condition1 AND condition2)- 如果
condition1和condition2都是true,AND运算符计算为true;否则它计算为false。(示例:condition1 AND condition2)
- 如果
The
ORoperator evaluates totrueifcondition1istrueor ifcondition2istrueor if bothcondition1andcondition2aretrue; otherwise it evaluates tofalse. (Example:condition1 OR condition2)- 如果
condition1是true或condition2是true或condition1和condition2都是true,OR运算符计算为true;否则它计算为false。(示例:condition1 OR condition2)
- 如果
The operand for a logical operator is either a Boolean expression or a single Boolean value.
- 逻辑运算符的操作数要么是布尔表达式,要么是单个布尔值。
学生活动 Student Activities
For relationships between two variables, expressions, or values:
- 对于两个变量、表达式或值之间的关系:
- Write expressions using relational operators.
- 使用关系运算符编写表达式。
- Evaluate expressions that use relational operators.
- 计算使用关系运算符的表达式。
For relationships between Boolean values:
- 对于布尔值之间的关系:
- Write expressions using logical operators.
- 使用逻辑运算符编写表达式。
- Evaluate expressions that use logic operators.
- 计算使用逻辑运算符的表达式。
