1# Python does not have a do-while loop. You can however simulate
2# it by using a while loop over True and breaking when a certain
3# condition is met.
4# Example:
5i = 1
6while True:
7 print(i)
8 i = i + 1
9 if(i > 3):
10 break
1//runs as long as the condition is true
2while(condition){
3//do what you want in here
4doStuff()
5}
1# A while loop is basically a "if" statement that will repeat itself
2# It will continue iterating over itself untill the condition is False
3
4python_is_cool = True
5first_time = True
6
7while python_is_cool:
8 if first_time:
9 print("python is cool!")
10 else:
11 first_time = False
12
13print("Done")
14
15# The while loop can be terminated with a "break" statement.
16# In such cases, the "else" part is ignored.
17# Hence, a while loop's "else" part runs if no break occurs and the condition is False.
18# Example to illustrate the use of else statement with the while loop:
19
20counter = 0
21
22while counter < 3:
23 print("Inside loop")
24 counter = counter + 1
25else:
26 print("Inside else")
1while 10 > 8:
2 print("Hello")
3while not False:
4 print("Hello")
5while True:
6 print("Hello")
7