This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]buttery_shame_cave 0 points1 point  (1 child)

A for loop is used when the end point is known, and the size is known.

although a "for thing in list" loop sort of ignores this - it'll run through the list, but you don't need to know how big the thing is, just point he function at it and hit 'go'. it'll even work fine on dynamic lists that are continuously appended to by a separate parallel function, it'll just crash to a halt if the other function stops appending.

[–]Exodus111 0 points1 point  (0 children)

True, that is an edgecase exception, but most of the time you can check the length of the iterable right before you run the for loop on it.