1 of 4

Let's Get Loopy

Requirements and Approach to

2 of 4

Requirements

  • Write each loop in a separate program
  • Use functions where indicated

3 of 4

Approach

  • decide if you need to use a for loop or a while loop?
    • In general, use a while loop if you are going to loop until a certain condition is reached
    • In general, use a for loop if you know how many times you need to loop or if you are looping over a set of things.
  • set up variable values before the loop for the first iteration of the loop
  • update/calculate variable values in the loop
  • test test test … start with small number of iterations and print
    • run the loop for just a few iterations to make sure it starts correctly
    • print out the variables in the loop to see their values for each iteration of the loop
      • print(f'{varName1=} {varName2=}')
      • NOTE: printing inside a loop that runs many iterations will be slooooow.

4 of 4

Or even better …

use the Thonny debugger