In python , there are two type of loops-
- for loop
- while loop
while loop are simple loop which run until the condition will not become false
Syntax :-
while(condition):
body of whileProgram
i=20
print("While loop start")
while(i>10):
print(i)
i=i-1
print("While loop ends")Output-
While loop start
20
19
18
17
16
15
14
13
12
11
While loop ends-in this program, we start value of i with 20 then in while, condition is become true then we print the value of i and decrease the value of i then at i ==10, condition will become false so that loop break automatically and terminate
while(1) //infinite loop because condition will always true
while(0) // condition is zero so not run