Selection - Lakelands Computing

Title
Go to content
Selection
Selection is a very important concept in programming. It is one of the three basic logic structures. It is often called a decision structure as it "decides" what code to run.

In selection a question is asked, and depending on the answer, the program takes one of two courses of action.

This structure is sometimes referred to as if then else:  

    • If Condition A is True
    • Then do this Action (X)
    • Else (otherwise) do this Action (Y) instead.

So in the Scratch example, if the answer is  9 then that condition is true and it will carry out the Then action and say "Correct." (Note - neither Scratch or Python use the word then in these statements - but it is implied)

In the Python example the condition is false because a does not equal b, (10 is not equal to 20) so the Else action will be carried out.. it will print "no"

See more on how Selection is done in Scratch here and Python here.
All Text copyright Lakelands Academy & Mr T Purslow 2020.
All images copyright free / creative commons unless otherwise stated.
You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
Back to content