ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Selection/Nested selection and precedence
J277 · 2.2.1

Unit 6 · Lesson 3

Nested selection and precedence

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Use nested selection and brackets to express decisions with the intended Boolean precedence.

Nested selection makes one decision only after another has succeeded. A combined Boolean expression can sometimes express the same rule more compactly, but its grouping must be clear. Brackets are evaluated first, then NOT, then AND, then OR. Add brackets whenever the intended grouping could be misunderstood.

Nested selection

A selection statement placed inside another selection statement.

Outer condition

The first condition that controls whether an inner selection is reached.

Inner condition

A condition evaluated only after its enclosing branch is entered.

Operator precedence

The order in which operators in a combined expression are evaluated.

Keep these in mind

  • An inner if is reached only when execution enters its outer branch.
  • Indentation shows nesting in Python; ERL also closes each nested if with its own endif.
  • Boolean precedence is brackets, NOT, AND, then OR.
  • Use brackets around alternatives that must be controlled by one earlier condition.
  • A Boolean variable can be used directly as a condition without == true.

Learning objective

Use nested selection and brackets to express decisions with the intended Boolean precedence.

Exam tip

For armed-system questions, group the sensors: systemArmed AND (doorActive OR windowActive). Test a disarmed system with an active sensor to check your logic.

Common mistake

systemArmed AND doorActive OR windowActive evaluates AND first, so an active window can trigger the result while the system is disarmed. Add brackets or use nested if statements.

PreviousNext