What is nested selection?
- Nested means to be 'stored inside the other'
- An example of nested selection is one IF statement inside of another
- It is worth noting that iteration can be nested as well and this can be seen in the iteration revision note
Examples of nested selection
// Prompt the user to enter a number
PRINT "Enter a number: "
test_score ← INPUT
// Outer statement to check the test_score is above 40
IF test_score > 40 THEN |
// Inner statement to assign the result from the test
IF test_score > 70 THEN
result ← "Distinction" ELSE IF test_score > 55 THEN
result ← "Merit" ELSE IF test_score > 40 THEN result ← "Pass"
ENDIF
|
ELSE result ← "Fail" ENDIF
// Output the result OUTPUT result |