CHAPTER 22 •
PYTHON
Python While Loop
Learn how to repeat code while a condition remains true.
01 What is this?
Learn how to repeat code while a condition remains true.
02 Syntax
Python Syntax
while condition:
statement
03 Example
Python Example
count = 1
while count <= 5:
print(count)
count += 1
04 Important Points
Make sure the loop condition eventually becomes false.
05 Common Mistakes
An incorrect condition can create an infinite loop.
06 Real World Use
While loops are useful for repeated processes and menus.
07 Practice This Topic
Now try the example yourself in the AIFA Python Editor.
- Read the example carefully.
- Change the values.
- Run the code.
- Observe the output.
- Try creating your own example.