Boolean CS Thinking Example 1

Follow the full solution, then compare it with the other examples linked below.

Example 1

easy
Evaluate each expression when x = 7: (a) x > 5, (b) x == 10, (c) x != 7, (d) x >= 7.

Solution

  1. 1
    Step 1: Substitute x=7x = 7 into each comparison.
  2. 2
    Step 2: Evaluate (a) 7>5β†’7 > 5 \to TRUE and (b) 7==10β†’7 == 10 \to FALSE.
  3. 3
    Step 3: Evaluate (c) 7!=7β†’7 != 7 \to FALSE and (d) 7>=7β†’7 >= 7 \to TRUE.

Answer

(a) TRUE, (b) FALSE, (c) FALSE, (d) TRUE.
Boolean expressions evaluate to TRUE or FALSE. They are the foundation of conditions in IF statements, loops, and filters. The operators >, <, ==, !=, >=, <= compare values.

About Boolean

A data type representing a logical value that can only be true or falseβ€”nothing else. Booleans are produced by comparison operators (==, <, >, !=) and consumed by control structures (if-statements, while-loops) to make decisions.

Learn more about Boolean β†’

More Boolean Examples