

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- How does the Java “foreach” loop work?
- Python - How to convert this while loop to for loop?
- How to convert a Python for loop to while loop?
- Java while loop
- do…while loop vs. while loop in C/C++
- How does tuple comparison work in Python?
- How does mkdir -p work in Python?
- How does Python dictionary keys() Method work?
- How does ++ and -- operators work in Python?
- 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?
- How does Overloading Operators work in Python?
- How to emulate a do-while loop in Python?
Advertisements