Why is 0 left out in the output when I use the continue statement within while loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is 0 left out in the output when I use the continue statement within while loop?

In this code without the continue statement, i = 0 while i<5: print(i) i += 1 the output was 0 1 2 3 4 But when I use the continue statement for the above code, i = 0 while i<5: i += 1 if i==3: continue print(i) the output was 1 2 4 5 I want to know why 0 is left out and 5 is added.

7th Dec 2022, 9:42 AM
Haru
Haru - avatar
1 Answer
+ 3
Because you assign 1 to i before the output. i = 1. You need to append the output before adding the number to the variable
7th Dec 2022, 10:01 AM
Knight
Knight - avatar