Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON TEXT / CHAPTER 03 / Learn / LESSON 06
Sixth class. for is convenient when you know the collection. while repeats as long as the condition is true.
The pattern is: prepare a counter, while condition:, body, update the counter. If you forget the update, the loop may never stop.
Mini example:
n = 1
while n <= 3:
print(n)
n = n + 1
print("done")The condition is checked before each iteration. When it becomes False, while ends and the program continues after the block.
Common mistake: putting n = n + 1 outside the body (or omitting it); or writing while n < 3 when you meant to include 3.
Learn: while repeats while the condition is true.
DECISION STANDBY
›