A definite loop is repeated a given number of times and we need it when we know how many times we want to repeat the iteration:
for i in range(5):
print(i)
It is also suitable for traversing Iterable objects:
l = [1, 2, 3, 4, 5]
for i in l:
print(i)
An indefinite loop is useful in cases where we don't know in advance how many times we should repeat the iteration:
i = int(input())
while (i != 0):
print(i)
i = int(input())
Comments
Leave a comment