Lecture 13 - Looping

Lecture Date: Wednesday, February 17

We’ll start by going over the at-home example.

Often there is code that we want our programs to repeat. This could be to have the program process all the items in a list, or do a number of tasks in order, or any number of other reasons. Along with if statements, loops are a core decision and control structure to write effective programs.

There are several ways to write loops in Python. We’ll discuss those all today.

  • while loop - a condition-controlled loop
  • for loop using the range operator- a count-controlled loop
  • for loop using the in operator with a list
  • while loops for input validation
  • nested loops

Here are some things we might try to build:

  • a shopping cart
  • the worst roman.py solution ever
  • average of a list of numbers
  • printing a square