Introduction: IterationΒΆ

A basic building block of all programs is to be able to repeat some code over and over again. In computing, we refer to this repetitive execution as iteration. In this section, we will explore some mechanisms for basic iteration.

With collections (lists and strings), a lot of computations involve processing one item at a time. For strings this means that we would like to process one character at a time. Often we start at the beginning, select each character in turn, do something to it, and continue until the end. This pattern of processing is called a traversal, or iteration over the characters. Similarly, we can process each of the items in a list, one at a time, iteration over the items in the list.

Next Section - The for Loop