Registry Synced

Control Flow

122 words
1 min read

Reading compass

Now · Branches

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.
python
score = 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.
python
total = 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.
Document outline

Keep your place and jump directly to a heading.

Table of contents

No note selected

Open a chapter to see its outline, backlinks, and sources here.