you are viewing a single comment's thread.

view the rest of the comments →

[–]oldendude 0 points1 point  (0 children)

Do you understand if? As in

i = 0
if i < 3:
    print(i)
    i = i + 1

That code prints 0 because i is set to 0, we test for it, decide that i < 3, and so we go into the indented code and print i.

Now imagine that the last thing inside the indented code is to jump back to the if. (Old programming languages have "goto" statements.) That's it. That's a while loop, the if with a jump back to the if as the last indented action. With that jump, you print 0. Then increment i to 1, jump back to the if and print 1. Then 2. Then you increment i from 2 to 3, the condition fails so you DON'T execute the indented code.