Lesson 4
Repeated Practice Makes Perfect
Chapter 3: While loops
While loops
Now we move on to the third basic building block, which is the repetition block.
We discussed the while
loop in Lesson 1.
What does the following code do? Try to guess first before running it to confirm.
n = 10
while n > 0:
print(n)
n = n - 1
print("Happy new year!!")
Also remember that you can nest another while
statement (or any building block) inside a loop.