You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Selection allows a program to make decisions and follow different paths based on conditions. This is one of the three fundamental programming constructs (alongside sequence and iteration) and is required for AQA 3.2 / OCR J277 2.2.
Without selection, programs can only execute instructions in a fixed order (sequence). Selection lets programs respond to different inputs and situations, making them useful in the real world. For example, a login system must check whether a password is correct before granting access.
The simplest form of selection is the IF statement, which executes a block of code only if a condition is True.
IF age >= 18 THEN
OUTPUT "You can vote."
ENDIF
if age >= 18:
print("You can vote.")
Key Point: In Python, the colon
:at the end of theifline and the indentation of the body are essential. In pseudocode, the block ends withENDIF.
An IF...ELSE provides two paths — one for when the condition is True and one for when it is False.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.