Note 7.9.1.
Introduction of the for statement causes us to think about the types of iteration we have seen. The
for
statement will always iterate through a sequence of values like the list of names for the party.Since we know that it will iterate once for each value in the collection, it is often said that a
for
loop creates a definite iteration because we definitely know how many times we are going to iterate. On the other hand, the while
statement is dependent on a condition that needs to evaluate to False
in order for the loop to terminate. Since we do not necessarily know when this will happen, it creates what we call indefinite iteration. Indefinite iteration simply means that we don’t know how many times we will repeat but eventually the condition controlling the iteration will fail and the iteration will stop. (Unless we have an infinite loop which is of course a problem.)