Home > front end >  Loop start from 2 instead of 1 in python continue statement
Loop start from 2 instead of 1 in python continue statement

Time:08-20

I am learning continue statement in python while loop. If I run a following code, the output shows from 2 instead of 1.

    a = 1
    while a <= 8:
        a  = 1
        if a == 5:
            continue
        print(a)

CodePudding user response:

You go through the body of the while condition once, 1 1 = 2 then print(2)

CodePudding user response:

a = 1 is coming before the print statement, that's why it's printing 2. Your a == 5 condition is also not executing because a is 2.

you can elaborate your question more if you haven't got the answer yet.

  • Related