Python while loop : While loop is used to iterate block of codes repeatedly until given condition return True. The main difference between while and for loop is that we use while loop when we are not certain if no of times required execution. In for loop we exactly know that how many times we need to run the loop. In python we discuss the while loop, the execution of the loop is repeatedly done till the condition becomes true. And when the condition becomes false, line after the loop in program executed. The while loop is used when it is possible to determine exact no of loop iterations in loop
Are known in advance.
In while loop python checks the condition if it is false then the loop terminates and control passed to next statement. In case if condition becomes true loop is executed and condition is check again. This process continues until condition is true. Once it becomes false loop is again terminated and passed to next statement.
Python while loop Flow chart:-
First step to check the Test Condition.
Then the test evaluate to True then it executes the code of while block.
After the one iteration of while block execution is done it again goes back to initial position and checks the test condition.
This process continues until the time Test condition evaluates to False.