Skip to content
Discussion options

You must be logged in to vote

Actually the file answers this itself — break is the intended demo there, and continue already gets its own loop three lines later. The file is showing both keywords, not making the mistake:

for num in range(10):
    if num == 5:
        break
    print(num)          # 0 1 2 3 4 — stop entirely

for num in range(5):
    if num == 2:
        continue
    print(num)          # 0 1 3 4 — skip one, keep going

Plus a third variant further down (for nut in range(16): if nut % 2 == 0: continue — keep only odds), so continue is demonstrated twice. The break loop's comment-worthy property is precisely that 6–9 never print: break exits the whole loop, where continue would have kept running. "Skip 5…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dab00gieman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants