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)