Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
670 views
in Python - Control Structures by (54.8k points)
closed by

Explain while loop with sample program.

1 Answer

+1 vote
by (49.1k points)
selected by
 
Best answer

The syntax of while loop in Python has the following syntax:

Syntax:

while:

statements block 1

In the while loop, the condition is any valid Boolean expression returning True or False. The else part of while is optional part of while. The statements block 1 is kept executed till the condition is True. If the else part is written, it is executed when the condition is tested False.

Recall while loop belongs to entry check loop type, that is it is not executed even once if the condition is tested False in the beginning.

Example: program to illustrate the use of while loop – to print all numbers from 10 to 15

i = 10 # initializing part of the control variable

while (i< = 15): # test condition

print (i, end = ’\t’) # statements – block 1

i = i + 1 # Updation of the control variable

Output:

10 11 12 13 14 15

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...