Neural Sync Active
Control Flow
Registry Synced
Control Flow
122 words
1 min read
Control Flow
Control flow decides which lines run and how many times they run.
Branches
An
if statement asks a yes/no question. Only the matching branch runs.pythonscore = 7 if score >= 8: badge = "gold" else: badge = "steady"
The condition is false, so
badge becomes "steady".Loops
A loop repeats a block. The safest reading habit is to track the loop variable and the state that changes.
pythontotal = 0 for n in [2, 4, 6]: total = total + n
The values of
total are 2, 6, then 12.Practice
For every loop, name:
- What changes each pass.
- What stays the same.
- What condition stops the loop.