ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Selection/Boolean expressions and comparisons
J277 · 2.2.1

Unit 6 · Lesson 1

Boolean expressions and comparisons

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Combine comparison operators with AND, OR and NOT to form correct Boolean expressions.

A condition is a Boolean expression: its result is true or false. Use ==, !=, <, >, <= and >= to compare values. Combine comparisons with AND when both must hold, OR when either may hold, and NOT when a result needs reversing. ERL writes these Boolean operators in uppercase; Python uses lowercase.

Boolean

A data type with exactly two possible values: true or false.

Boolean expression

An expression that evaluates to either true or false.

Comparison operator

An operator such as == or >= that compares two values and produces a Boolean result.

AND

A Boolean operator that is true only when both conditions are true.

OR

A Boolean operator that is true when either condition, or both conditions, are true.

NOT

A Boolean operator that reverses true and false.

Keep these in mind

  • == compares values; = assigns a value.
  • < and > exclude the boundary, while <= and >= include it.
  • Repeat the variable in every comparison.
  • A valid range uses AND; values outside that range can be found with OR.
  • For two allowed text choices, equality uses OR and inequality uses AND.

Learning objective

Combine comparison operators with AND, OR and NOT to form correct Boolean expressions.

Exam tip

Write a complete comparison on both sides of a Boolean operator: height >= 40 AND height <= 180, not height >= 40 AND <= 180.

Common mistake

room == "basic" OR "premium" is incomplete. Write room == "basic" OR room == "premium". To reject both choices, use != with AND, not OR.

PreviousNext