Python while loop

The while Loop
The while loop works with the conditions i.e. as long as a condition is true then the loop will executed.
For e.g. if we want to print i as long as i is less than 6:

i = 1

while i < 6:

     print(i)

     i += 1


If you are using while loop then the relevant variable used in the loop must be ready like in this example we need to define define a variable which will represent index(in this case we used i) and it is set to 1.
The break Statement
If we are using break statement in the while loop then we can stop the loop even after the condition is true.
For e.g. if we want to exit from the loop when i is 3, then we can write the following code:

i = 1

while i < 6:

     print(i)

     if i == 3:

         break

     i += 1


The continue Statement
If we are using the continue statement then we can stop the current iteration and continue to the next iteration.
For e.g. is we want to continue to the next iteration if i is 3 i.e. when the value of i is 3 then it will skip that iterartion and will continue with the next iteration:

i = 0

while i < 6:

     i += 1

     if i == 3:

         continue

     print(i)