Question #145521

Using examples, explain the difference between a definite loop and an indefinite loop.

Expert's answer

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())

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS