Python while loop

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.

Python while loop syntax

                       While condition

                             # body of while

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:-

while loop python
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.

4. Nested while loop in Python :-

The while loop present inside another while loop it is called as nested while loop. The nested while loop is while statement inside another while statement.        In this execution one iteration of outer loop is in tally executed after that the inner loop is executed. If the condition of inner loop is satisfied program moves to the next iteration of outer loop finish. In python the break and continue statements are used. The “break” statement immediately terminate loop entirely. The program execution proceeds to first statement in body. The “continue” statement immediately terminate current loop. Execution goes to the top of loop control expression and execute again.
Syntax for nested while loop is:-
               While expression:
                          While expression:
Statement(s)
Statement(s)
The note on loop nesting is that you can put any type of loop inside any type of loop.
As the  for loop can be present in while loop and the vice versa.
Example:-
i=1
j=5
while i<3:
 while j<7:
 print(i”,”,j)
j=j+1
i=i+1
O/p:-
1,5
2,6

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India