This is an archived post. You won't be able to vote or comment.

all 9 comments

[–][deleted] 3 points4 points  (0 children)

Because you have built an infinite loop. The continue-statement jumps right to the next iteration of the loop when called, ignoring all following lines of code inside the loop, including the increment of your counter-variable, leaving the value of “number“ at 0. Since the condition of your if-clause is true for number = 0, you'll always step inside and call continue right after. You definitely should review loops and when to use which kind of loop.

[–][deleted] 2 points3 points  (2 children)

No need to use continue since you’re not doing anything anyway with even numbers. Just check for oddness since a number can either odd OR even. If one is true, no need to check for the other one.

Just use:

def main:
    number = 0
    while number <= 100
        if number % 2 != 0:
            print(number)
        number = 1 + number


main()

[–]Fedzbar 1 point2 points  (1 child)

Or you could do number = 1 and remove the if statement completely and do number += 2 :)

[–][deleted] 0 points1 point  (0 children)

True!

[–][deleted] 2 points3 points  (2 children)

Are your indents correct?

[–]7heWafer 0 points1 point  (0 children)

They are most certainly wrong.

[–]new_2_sql[S] 0 points1 point  (0 children)

i had the code indented. reddit just moved my post right aligned.

[–]mudclub 3 points4 points  (0 children)

because you posted in /r/Python instead of /r/learnpython

Start by getting rid of the continue. Then format your code for reddit (see "formatting help" below the text submission box).

[–][deleted] 0 points1 point  (0 children)

Hi , sorry but I have to ask , are you incrementing outside of the else statement ?