Skip to content

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

  1. A Boolean value is either true or false.

    • 布尔值要么是真要么是假。
  2. The exam reference sheet provides the following relational operators: =, ≠, >, <, ≥, and ≤.

    • 考试参考表提供以下关系运算符:=、≠、>、<、≥和≤。
  3. 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计算为真;否则,它计算为假。
  4. The exam reference sheet provides the logical operators NOT, AND, and OR, which evaluate to a Boolean value.

    • 考试参考表提供逻辑运算符NOT、AND和OR,它们计算为布尔值。
  5. The NOT operator evaluates to true if the condition is false; otherwise it evaluates to false. (Example: NOT (condition))

    • 如果conditionfalseNOT运算符计算为true;否则它计算为false。(示例:NOT (condition)
  6. The AND operator evaluates to true if both condition1 and condition2 are true; otherwise it evaluates to false. (Example: condition1 AND condition2)

    • 如果condition1condition2都是trueAND运算符计算为true;否则它计算为false。(示例:condition1 AND condition2
  7. The OR operator evaluates to true if condition1 is true or if condition2 is true or if both condition1 and condition2 are true; otherwise it evaluates to false. (Example: condition1 OR condition2)

    • 如果condition1truecondition2truecondition1condition2都是trueOR运算符计算为true;否则它计算为false。(示例:condition1 OR condition2
  8. The operand for a logical operator is either a Boolean expression or a single Boolean value.

    • 逻辑运算符的操作数要么是布尔表达式,要么是单个布尔值。

学生活动 Student Activities

  1. For relationships between two variables, expressions, or values:

    • 对于两个变量、表达式或值之间的关系:
    • Write expressions using relational operators.
      • 使用关系运算符编写表达式。
    • Evaluate expressions that use relational operators.
      • 计算使用关系运算符的表达式。
  2. For relationships between Boolean values:

    • 对于布尔值之间的关系:
    • Write expressions using logical operators.
      • 使用逻辑运算符编写表达式。
    • Evaluate expressions that use logic operators.
      • 计算使用逻辑运算符的表达式。

基于 VitePress 构建的 AP CSP 学习平台