Selection: IF and CASE Cambridge IGCSE Computer Science (9–1) revision
Not started
Learn it
In plain words
A program that does exactly the same thing every time is not much use. Selection lets it choose: test a condition, and run one set of statements or another depending on the answer.
5 things to know
- Sequence means statements are carried out one after another, in order. Selection means choosing which statements to carry out.
- IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF. The statements after THEN run when the condition is true. Those after ELSE run when it is false.
- The ELSE part can be left out if nothing needs to happen when the condition is false.
- CASE OF tests one variable against several values. Each value has its own statement, and OTHERWISE covers anything that does not match. It ends with ENDCASE.
- A nested IF is an IF statement inside another one. It is used when a second decision depends on the first.
Worked example
Age holds 15. What is output by: IF Age >= 18 THEN OUTPUT "Adult" ELSE IF Age >= 13 THEN OUTPUT "Teen" ELSE OUTPUT "Child" ENDIF ENDIF?
- First condition: is 15 >= 18? No. So the ELSE part runs.
- Second condition: is 15 >= 13? Yes. So "Teen" is output.
- The final ELSE is skipped.
Tips and tricks
- Every IF needs its ENDIF and every CASE OF needs its ENDCASE. Count them, especially when one is nested inside another.
- Use CASE when one variable is compared with a list of values. Use IF for ranges, or when two different variables are tested.
It lands in your notebook with its questions as flashcards.
Selection: IF and CASE: 6 questions and answers
These are the quiz’s questions. Do the quiz first, then come back here for the ones that got you.
What is selection?
IF and CASE are selection statements.
Number holds 8. What does IF Number > 10 THEN OUTPUT "Big" ELSE OUTPUT "Small" ENDIF output?
8 > 10 is false, so the ELSE part runs.
Which keyword ends an IF statement?
ENDCASE ends a CASE statement.
In a CASE statement, what is OTHERWISE for?
It catches every value not listed.
What is a nested IF?
The inner decision depends on the outer one.
Score holds 50. What does IF Score >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF output?
50 >= 50 is true.
Quiz
6 questions
Tap an answer and you’ll see straight away whether it’s right, and why.
Worksheet
2 questions, 5 marks. Write your answers on paper, then check them.
Selection: IF and CASE
Cambridge IGCSE Computer Science (9–1) 0984 · 5 marks · papermunch.org
Name ______________________________ Date ______________
Write a pseudocode IF statement that outputs "Hot" if Temp is more than 30 and "Mild" if not.[3]
Show answerHide answer
IF Temp > 30 THEN OUTPUT "Hot" ELSE OUTPUT "Mild" ENDIF
Explain when a CASE statement is more suitable than IF statements.[2]
Show answerHide answer
When a single variable has to be compared with several different values, each needing its own action. It is clearer than many separate IF statements.
Answers: Selection: IF and CASE
- 1. IF Temp > 30 THEN OUTPUT "Hot" ELSE OUTPUT "Mild" ENDIF
- 2. When a single variable has to be compared with several different values, each needing its own action. It is clearer than many separate IF statements.



