ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Selection/If, elseif and else
J277 · 2.2.1

Unit 6 · Lesson 2

If, elseif and else

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Write correctly ordered if, elseif/elif and else branches in ERL and Python.

Selection lets a program choose what to do. An if branch runs when its condition is true. An else branch handles every remaining case. Add elseif in ERL or elif in Python when there are several possible conditions. The program takes the first true branch, so their order matters.

Selection

Using a condition to decide which path through a program is executed.

Branch

One possible path through a selection statement.

if

The first condition in an if selection structure.

elseif / elif

A later condition checked only when all earlier branches were false.

else

The fallback branch used when no earlier condition was true.

Keep these in mind

  • ERL uses if ... then and closes the structure with endif.
  • ERL writes elseif as one word; Python writes elif and uses colons and indentation.
  • else has no condition.
  • Only the first true branch in one if/elseif/else chain runs.
  • For threshold grades, test the highest threshold first.

Learning objective

Write correctly ordered if, elseif/elif and else branches in ERL and Python.

Exam tip

When completing ERL, include then after every if or elseif condition and one endif after the complete chain.

Common mistake

Putting score >= 40 before score >= 70 makes a score of 80 take the Pass branch. Check more specific or higher thresholds first.

PreviousNext