break
Exit the nearest loop early, for example when the searched student is found.
if, loops, range(), break and continue
Unit 2 · Control flow
Control flow is the order in which Python follows instructions. Conditions act like a decision at a school gate; loops repeat a job for each student or until a condition changes.
if statement checks a rule before choosing a path. A loop checks a class list or counter so you do not have to write the same instruction again and again.marks = [82, 35, 91]
for mark in marks:
if mark >= 40:
print(mark, "→ pass")
else:
print(mark, "→ retry")Output
Your program's output will appear here.
NameError: name 'mark' is not defined
NameError: A name was used before Python could find a variable or function with that name.
IndexError: list index out of range
IndexError: The requested position is outside the items in this list or sequence.
KeyError: 'email'
KeyError: That key does not exist in this dictionary.
TypeError: can only concatenate str (not "int") to str
TypeError: This operation does not work with the kind of value it received.
ZeroDivisionError: division by zero
ZeroDivisionError: A number cannot be divided by zero.
SyntaxError: invalid syntax
SyntaxError: Python could not understand the structure of this line. Check spelling, brackets, colons, and quotes.
IndentationError: expected an indented block
IndentationError: The spaces at the start of a line do not match Python's block structure.
Interactive line-by-line trace
Select a decision or loop, then advance one instruction at a time and watch the variables change.
1marks = [82, 35, 91]2for mark in marks:3 if mark >= 40:4 print(mark, "→ pass")5 else:6 print(mark, "→ retry")
Current instruction · 1 / 11
Store the class marks in a list.
Variables and result
marks → [82, 35, 91]
marks list created
range() createsThe stop number is not included. A positive step counts upward; a negative step counts downward.
list(range(-2, 8, 2))=[-2, 0, 2, 4, 6]Exit the nearest loop early, for example when the searched student is found.
Skip the rest of this turn and check the next item in the loop.
Do nothing for now; it keeps an unfinished block syntactically valid.
Leave a function and optionally send its result back to the caller.
Edit the score and add an else branch that prints “Retry” when the score is below 40.
# Task: print Pass for 40 or above, otherwise print Retry.
score = 35
if score >= 40:
print("Pass")
# Add the else branch hereOutput
Your program's output will appear here.
NameError: name 'mark' is not defined
NameError: A name was used before Python could find a variable or function with that name.
IndexError: list index out of range
IndexError: The requested position is outside the items in this list or sequence.
KeyError: 'email'
KeyError: That key does not exist in this dictionary.
TypeError: can only concatenate str (not "int") to str
TypeError: This operation does not work with the kind of value it received.
ZeroDivisionError: division by zero
ZeroDivisionError: A number cannot be divided by zero.
SyntaxError: invalid syntax
SyntaxError: Python could not understand the structure of this line. Check spelling, brackets, colons, and quotes.
IndentationError: expected an indented block
IndentationError: The spaces at the start of a line do not match Python's block structure.
IndentationError: expected an indented block
After a line ending in a colon, indent the instructions that belong to it.
The spaces at the start of a line do not match Python's block structure.
SyntaxError: invalid syntax
A missing colon after if, for, or while can stop Python understanding the statement.
1. What does range(2, 6) produce?
2. When should you use a while loop?
The trace uses the same scores shown in the working Python example.