A loop lets you repeat instructions multiple times without writing the instructions out multiple times.


create a variable
call a function
create a variable
call a function
create a variable
call a function....


Repeat this 15 times:
  create a variable
  call a function

for loop, or a count-controlled loop

  • executes a set of instructions for a specified number of times
  • used if you know the number of times you need to repeat the instructions

iteration – one pass through the instructions

while loop, or condition-controlled loop

  • repeats a set of instructions while that condition is true.
While there are pink tiles available:

for each loops

We define a sequence of desired tile colors (a list), and tell the computer to repeat the instructions for each item in the sequence. Here’s an example list:

festiveList = ['pink', 'green', 'red', 'pink', 'green', 'red' ]

and the loop would look like:

For each color in festiveList:

The larger the sample size and the more diverse your dataset is, the more confident you’ll be in your results.

Leave a Reply