#
WHILE loop in Python
This tutorial give you some example of using WHILE loop in Python.
Using WHILE loop in Python is very easy. Here are some examples:
Example #1
var1 = 4
while(var1 > 0):
print('var1= '+str(var1))
var1 = var1-1;
print ("END Program")
And here you can see the execution of the Python code in PyCharm using a WHILE simple loop:
Example #2
var1 = 4
while(var1 > 0):
print('var1= '+str(var1))
var1 = var1-1
if var1 == 2:
break
print ("END Program")
And here you can see the execution of the Python code in PyCharm using a WHILE simple loop with break:
Example #3
var1 = 4
while(var1 > 0):
print('var1= '+str(var1))
var1 = var1-1
pass
if var1 == 2:
continue
print("END while loop")
print ("END Program")
And here you can see the execution of the Python code in PyCharm using a WHILE simple loop with continue and pass: