Skip to main content

Python While Loop

The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true.

As long as the condition that follows the while keyword is true, the block following the while statement will continue to be executed over and over again.

Syntax of While loop

while <expr>:


while True:

The easiest way to specify an infinite loop in Python is to use the while keyword with an expression that is always true.

Submitted by devanshi.srivastava on June 3, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.