Python While Loop

In this example, the condition for while will be True as long as the counter variable (count) is less than 3. 

Python




# Python program to illustrate
# while loop
count = 0
while (count < 3):
    count = count + 1
    print("Hello Geek")


Output

Hello Geek
Hello Geek
Hello Geek

Infinite while Loop in Python

Here, the value of the condition is always True. Therefore, the body of the loop is run infinite times until the memory is full.

Python




age = 28
  
# the test condition is always True
while age > 19:
    print('Infinite Loop')


Python While Loop

Python While Loop is used to execute a block of statements repeatedly until a given condition is satisfied. When the condition becomes false, the line immediately after the loop in the program is executed.

Syntax of while loop in Python

while expression:
statement(s)

Similar Reads

Flowchart of Python While Loop

...

Python While Loop

In this example, the condition for while will be True as long as the counter variable (count) is less than 3....

Control Statements in Python with Examples

...

Python while loop with Python list

...

Single statement while block

Loop control statements change execution from their normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Python supports the following control statements....

Python While Loop Exercise Questions

...