Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Selection

IF and Else

All topicsPractise exam questions
Knowledge organiser

Selection

301.9a

Choose between two paths.

What you need to know

An if statement checks a condition — if True, the indented block runs. An optional else block runs when the condition is False. This lets the program choose between two paths.

Key points

  • if condition: runs block when True
  • else: runs when the condition is False
  • The condition must be a Boolean expression
  • Only one branch executes — never both

Code examples

IF and Else
python
age = int(input("Age: "))
if age >= 18:
    print("Adult")
else:
    print("Minor")