9_3_3

WHAT: Understand the difference between definite and indefinite iterations

HOW:

Activity 1 - READ

Definite - we know how many times a loop will run before it starts.

Indefinite - we don't know how many times a loop will run until it is finished.

The two loops that we use in Python are a for loop and a while loop. Which one is definite and which is indefinite?

Below is some pseudocode for each type of loop to help you answer:

For loop

FOR i in 1 TO 5
   OUTPUT i

While loop

WHILE i != 5
   OUTPUT i
   INPUT i

When we write a for loop, we know how many times it will loop before it starts. This means that a for loop is a definite loop.

When we write a while loop, we are testing a condition. That loop will run for as long as the condition is true. We don't necessarily know when the condition will become false so it is an indefinite loop.

Activity 2 - Re-visit

You should be really familiar with for loops and while loops at this point. If you aren't then watch these videos again:

CHECK:

EMBED:

  1. Write a for loop that will display the alphabet.
  2. Write a while loop that will display the alphabet.
  3. Which one is more efficient?
  4. Based on your knowledge of definite and indefinite loops, which one SHOULD you use the display the alphabet?

CLASSROOM IDEAS:

This lesson is basically a re-cap with some know keywords for the students to learn. If they are finding this concept a struggle then it may be a good idea to pause here and refresh those coding skills.