Lesson 09
continue Statement — Skip to Next Iteration
Use Python continue in for and while loops to skip the rest of the current iteration. Filter vowels, skip characters, and keep the loop else block behavior.
Beginner25 min
continue statement
continueis a keyword.continuesends PVM to the top of the loop without executing statements aftercontinuefor the current iteration only.- Must be used inside loops.
- When
continueis used, theelsepart of the loop still executes if the loop condition eventually becomes false (unlikebreak).
Syntax — continue in for loop
for varname in iterable_object:
if test_cond:
continue
statement_1 # skipped this iteration when continue runs
statement_2Syntax — continue in while loop
while test_cond:
if test_cond:
continue
statement_1
statement_2Example 1 — Skip 'T' in for loop
s = "PYTHON"
for ch in s:
if ch == "T":
continue
else:
print(ch)
else:
print("for loop---else part")Example 2 — Skip 'H' and 'Y' in while loop
s = "PYTHON"
i = 0
while i < len(s):
if s[i] == "H" or s[i] == "Y":
i = i + 1
continue
print(s[i])
i = i + 1
else:
print("while..else part")Example 3 — Print consonants only
line = input("Enter a Line of Text:")
for ch in line:
if ch.lower() in ["a", "e", "i", "o", "u"]:
continue
else:
print(ch, end="")continue vs break
break |
continue |
|
|---|---|---|
Loop else |
Skipped | Still runs if loop ends normally |
| Current iteration | Stops loop | Skips remaining statements |
| Next step | Exit loop | Next iteration |
Next: File 10 — pass Statement
Loading playground…