Selection CS Thinking Example 1

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

Example 1

easy
Trace this code: SET age = 15. IF age >= 18 THEN OUTPUT 'Adult' ELSE OUTPUT 'Minor'.

Solution

  1. 1
    Step 1: age = 15.
  2. 2
    Step 2: Check condition: is 15 >= 18? No.
  3. 3
    Step 3: Execute the ELSE branch: output 'Minor'.

Answer

'Minor'
Selection (IF-ELSE) allows a program to choose between two paths based on a condition. Only one branch executes depending on whether the condition is true or false.

About Selection

Choosing which block of code to execute based on whether a condition is true or false. Selection allows programs to make decisions, following one path when a condition holds and a different path otherwise, using constructs like if, else-if, and else.

Learn more about Selection โ†’

More Selection Examples