
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How does Python while loop work?
while statement is very popular looping statement in many languages including Python. Is general usage is −
while expr==True: stmt1 stmt2 .....
The block of statements with increased indent after : symbol will be repeatedly executed as long as expr remains true. Obviously, certain provision must be there inside the block which will eventually make expr to be false, otherwise the loop will be an infinite one.
Easiest way to do this is to form a counted loop. For that a counting variable is to be initialized before looping body and it is incremented on every iteration till counting variable reached desired count.
x=0 if x<10: x=x+1 print (x)
- Related Articles
- How does the Java “foreach” loop work?
- In electric motors, how does a rectangular loop work?
- Python - How to convert this while loop to for loop?
- How to convert a Python for loop to while loop?
- Difference between for loop and while loop in Python
- How to emulate a do-while loop in Python?
- How does a Python interpreter work?
- do…while loop vs. while loop in C/C++
- Java while loop
- How does tuple comparison work in Python?
- How does underscore "_" work in Python files?
- How does garbage collection work in Python?
- How does class inheritance work in Python?
- How does issubclass() function work in Python?
- How does isinstance() function work in Python?

Advertisements