// Control Flow
pass / continue / break — The Full Picture
The idea!
You've covered pass, continue, break, and for...else.
This is your reference. Everything in one place.
Come back here whenever you need a reminder.
pass — the silent keeper
Does nothing. Holds the space.
for letter in "Bull":
pass # valid — no error, no output
if score >= 60:
pass # placeholder — come back later
Use it when Python requires a block but you're not ready to fill it in yet.
continue — the polite skip
Skips the rest of the current iteration. Loop keeps going.
for letter in "Bull":
if letter == "u":
continue # skip "u", move to next
print(letter)
# B / l / l
break — the emergency exit
Stops the loop immediately. No more iterations.
for letter in "Bull":
if letter == "u":
break # stop everything
print(letter)
# B
for...else
else runs when the loop completes without break. Skipped if break fired.
for letter in "Bull":
if letter == "x":
break
else:
print("No x found.") # runs — loop completed without break
# No x found.
Search pattern — the classic use case
word = input("Enter a word: ")
target = input("Enter a letter: ")
for letter in word:
if letter == target:
print(f"Found '{target}'.")
break
else:
print(f"'{target}' not found.")
The three in one block
for letter in "RedHorn":
if letter == "d":
pass # placeholder — handle later
if letter == "e":
continue # skip "e"
if letter == "R":
break # stop at "R" — wait, R is first
print(letter)
Each one does something different. None of them are interchangeable.
Common Mistakes
passdoes nothing — don't use it when you meancontinuebreakalways needs a condition — alone it stops on the first iterationelseis skipped whenbreakfirescontinueandbreakonly work inside loops
What you should understand now
pass— does nothing, holds the spacecontinue— skips the current iteration, loop keeps goingbreak— stops the loop entirelyfor...else—elseruns only when loop completes withoutbreak- Three different tools. Three different jobs. Not interchangeable.
// 0 comments
// No comments yet. Be the first.
// leave a comment