Python – While Loop

Python Loops

In loops, the statement are executed sequentially till the condition satisfied. The first statement in a function is executed first, followed by the second, and so on. Using Loops we can executed block of code for several times.

Python have two types of loops

StudyGyaan - Python Tutorial - While loop

Python While Loop

While loop we can execute a set of statements as long as a condition is true.

count = 1
while i < 6:
  print(i)
  count = count + 1

We use counter (variable-count) in while so that its does not go into infinite loop.

# While Loop

count = 1

while (count < 10):
if(count == 5):
print("Count", count)
count = count + 1
else:
print("Else Count", count)
Filed under: Python

No comment yet, add your voice below!


Leave a Reply