You are here: Home / Topics / While loop in python

While loop in python

Filed under: Python on 2022-08-31 16:27:46

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

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

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


About Author:
Y
Yogesh     View Profile
I am Yogesh Sharma. I found this website very useful for all the students. It is a very good website for learning thousands of multiple choice questions. Basically it is like a community website. Everyone can add questions so am I. I will add mcqs in this website to help you.