Unable to open this exercise
Common exam pitfall
Students often use && or || instead of uppercase AND or OR in Cambridge pseudocode.
Students often confuse AND with OR when testing ranges.
Selection is a fundamental programming construct that allows an algorithm to choose alternative execution paths based on whether a conditional expression evaluates to TRUE or FALSE.
1. Single and Two-Way Selection
Syntax:
IF <Condition> THEN
// Code executed when Condition is TRUE
ELSE
// Code executed when Condition is FALSE
ENDIF
- The
ELSEclause is optional if no action is required when the condition is false. - Every
IFstatement must terminate with a matchingENDIF.
2. Multi-Way Nested Selection
When selecting between three or more outcomes, IF statements can be nested inside the ELSE branch:
IF Mark >= 80 THEN
Grade <- "A"
ELSE
IF Mark >= 70 THEN
Grade <- "B"
ELSE
IF Mark >= 60 THEN
Grade <- "C"
ELSE
Grade <- "U"
ENDIF
ENDIF
ENDIF
Notice that three opened IF statements require three matching ENDIF statements at the close.
3. Logical Operators in Conditions
Compound conditions combine multiple relational comparisons using Boolean operators:
Operator | Meaning | Example |
|---|---|---|
| Evaluates to |
|
| Evaluates to |
|
| Inverts the logical state ( |
|
AI Socratic Tutor
Need guidance? Ask a question or use the hint below.
AI Socratic Tutor is an All-Access Benefit
Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.
You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.
Exam-Style Check: Logical Compound Conditions in Selection
• Multiple ChoiceWhich Cambridge pseudocode condition correctly checks if a student's age is between 11 and 18 inclusive?
Interactive exercises for Module 2 and beyond require an active plan.