30-Days-Of-Python icon indicating copy to clipboard operation
30-Days-Of-Python copied to clipboard

corrected while loop code

Open chinnaji opened this issue 3 years ago • 0 comments

In the python while loop example the code will only output 1,2,3 because the code after the continue statement will never be reached when count ===3

count = 0
while count < 5:
    count = count + 1
    if count == 3:
        continue
    print(count)

Here is my proposed code, i've tested it and it works.

count = 0
while count < 5:
    count = count + 1
    if count == 3:
        continue
    print(count)

# The above while loop only prints 0, 1, 2, 4 and 5 (skips 3).

chinnaji avatar Jun 13 '22 23:06 chinnaji