Bird
0
0

Analyze the output of this code:

hard📝 Application Q9 of 15
Python - While Loop

Analyze the output of this code:

i = 0
while i < 4:
    if i == 1:
        i += 1
        continue
    print(i)
    i += 1
else:
    print('Done')
A0 1 2 3 Done
B0 2 3 Done
C0 2 3
D0 1 2 3
Step-by-Step Solution
Solution:
  1. Step 1: Loop iteration

    i starts at 0, prints 0.
  2. Step 2: When i == 1

    The continue skips printing 1 and increments i to 2.
  3. Step 3: Prints 2 and 3

    Both are printed as normal.
  4. Step 4: Else block

    Since loop ends normally, 'Done' is printed.
  5. Final Answer:

    0 2 3 Done -> Option B
  6. Quick Check:

    Continue skips print but else runs after loop ends [OK]
Quick Trick: Continue skips iteration, else runs if no break [OK]
Common Mistakes:
MISTAKES
  • Printing skipped value 1
  • Assuming else won't run after continue
  • Confusing continue with break

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes