KS3 Computing/Selection

Selection
Selection allows us to add an additional level of control to our programs. When we introduce Selection, the computer will only run an instruction IF a specified condition is true or false. Otherwise it will not run that code / instruction. For example:

The print command above will only run IF the specified condition (age > 16) is true. If it is not true (e.g. age is 13), that line of code will not run, it will be ignored.

if / else if / else
You can also have several alternative options using the IF-ELIF-ELSE constructs in Python (though all languages provide similar). For example:

You can nest IF statements inside one another to build even more flexibility.

Another example of Selection is called the CASE statement. We do not usually look at the Case statement at KS3.