https://www.plus2net.com/python/while...
Python checks the condition and execute the code block by using where. if the condition is True then it executes the code block under where and if condition is false then it executes the code block under else. However else is optional. If else part is not there and where is false then no code block is executed. Unlike for loop we have to use one incremental counter inside while loop and at the begin of each loop the condition is check.
We have to care full and not to create such conditions where the condition never became false, in such case it will became infinite loop and it will never stops.
Basic code for while loop is here
I=0
While(I less than 5):
Print(i)
I=i+1
We can add else part ( optional )
else:
print("Outside the loop but inside the else")
After completing the while loop the execution jumps to execute the code block within else part.
Understanding continue and break
By using continue we can skip the code execution for rest of the loop and jump to starting of the loop
By using break we will come out of the loop and execution continues for rest of the program.
Else
Else part is executed after completing for loop execution. This else part of the code gets executed even if the loop encounters continue command, however the else part is skipped when the loop is terminated by using break statement.
To understand how the Else code block check this example on how to find out the input number is prime number or not.
Example
num=int(input("Enter the number you want to check : "))
i=2
while(I less than num/2):
if(num%i == 0):
print(num, " is not a prime number")
break;
i=i+1
else:
print(num , " is a prime number")