Step-by-step execution:
-
Initial value: i = 0
Iteration 1:
-
Condition: i < 5 → 0 < 5 ✅
i += 1 → i = 1
if i == 3 → 1 == 3 ❌
print(i) → prints 1
Iteration 2:
-
Condition: i < 5 → 1 < 5 ✅
i += 1 → i = 2
if i == 3 → 2 == 3 ❌
print(i) → prints 2
Iteration 3:
-
Condition: i < 5 → 2 < 5 ✅
i += 1 → i = 3
if i == 3 → 3 == 3 ✅ → continue triggers
continue means: skip the rest of this loop (so print(i) is not executed).
-
Nothing printed.
Iteration 4:
-
Condition: i < 5 → 3 < 5 ✅
i += 1 → i = 4
if i == 3 → 4 == 3 ❌
print(i) → prints 4
Iteration 5:
-
Condition: i < 5 → 4 < 5 ✅
i += 1 → i = 5
if i == 3 → 5 == 3 ❌
print(i) → prints 5
✅ Final Output:
1 2 4 5
๐ The key point: continue skips printing when i == 3, but the loop keeps running.


0 Comments:
Post a Comment