while loop in python by R4R Team

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 while

program -

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 automaically and terminate

while(1) //infinte loop because condition will always true

while(0) // condition is zero so not run

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!