Answer to Question #145521 in Python for Nhlanhla

Question #145521
Using examples, explain the difference between a definite loop and an indefinite loop.
1
Expert's answer
2020-11-23T06:38:41-0500

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS