98.0k views
1 vote
How do you use a while loop in python

1 Answer

5 votes

Answer:

The syntax of while loop is:

while condition:

statement - 1

statement - 2

" " " "

statement - n

Step-by-step explanation:

Required

How while loop is used in Python

While loop is used for repititive operations as long as a certain conditions is true.

Take for instance a program to print from 1 to 10.

This can be achieved using the following while statement

num = 0

while num < 10:

print(num+1)

num+=1

The indented code is repeated as long as num < 10.

Hence, the general syntax of the while loop is:

while condition:

statement - 1

statement - 2

" " " "

statement - n

User JazzMaster
by
4.2k points