Skip to main content
Engineering LibreTexts

5.7: Loop patterns

  • Page ID
  • Often we use a for or while loop to go through a list of items or the contents of a file and we are looking for something such as the largest or smallest value of the data we scan through.

    These loops are generally constructed by:

    • Initializing one or more variables before the loop starts
    • Performing some computation on each item in the loop body, possibly changing the variables in the body of the loop
    • Looking at the resulting variables when the loop completes

    We will use a list of numbers to demonstrate the concepts and construction of these loop patterns.

    • Was this article helpful?