C3.1 Solve problems and create computational representations of mathematical situations by writing and executing code, including code that involves sequential, concurrent, repeating, and nested events.

Activity 1: Repeating Patterns and Repeating Events


  • Begin a mathematical conversation with students related to repeated patterns by showing them an illustration like the one shown below:
The 4 cards of the ace of a deck of cards.
  • Ask students the following question: What happens in this pattern?

Possible answers:

ABAB pattern for the number attribute ("ace, two" is repeated).

ABCD pattern for the symbol attribute ("hearts, diamonds, spades, clubs" is repeated).

AABB pattern for the colour attribute ("red, red, black, black" is repeated).

  • Ask students questions to help them understand that there is more than one structure to describe a pattern. This prepares them to explore the nested structure of the loop within the loop.
  • Then ask students the following question: How can the pattern be extended?
  • Form small, heterogeneous groups and invite students to discuss the different ways they saw the pattern. Listen to their reasoning.
  • Ask students to write a pseudo code for a robot that must deal cards according to a pattern.

Example of Pseudocode

Repeat (number of repetitions) times

Repeat (2 times)

Place an ace

Place a two

Change colour

This example of pseudocode will give a pattern of the type "ace black, two black, ace red, two red", and this, for the number of repetitions of the pattern defined by the first loop.

Students can repeat the activity creating a different pattern using cards.

Activity 2: Financial Literacy and Nested Events


A student in Grade 4 does extra household chores for her parents to earn spending money. Her parents pay her an amount by the hour of work. She receives payment on Friday each week and decides to save the money earned.

Write code that uses nested events to predict the value of savings after a certain amount of time.

This situation is open-ended "by design" to start where students are at in their understandings and to move their thinking forward by encouraging students to use variables in their code.

Sample Code

Code Result (output)
Image Blocks of code: Events block stating “start on when green flag is clicked”. Variables block stating “set amount earned per hour worked to ‘0’.” Variables block stating “hours per hour worked to ‘0’.” Variables block stating “weekly pay to ‘0’.” Sensing block stating “ask ‘how much money do you earn per hour of work?’ and wait”. Variables block stating “set amount earned per hour worked to motions block stating “answer ‘0’.” Sensing block stating “’how many hours do you work per week?’ and whit”. Variables block stating “set hours per week to motions block stating “answer”. Controls block stating “repeat 52”. Inside 2 nesting blocks. Controls block stating “repeat” variable block “hours per week”. Variable block “change amount saved by the amount earned per hours worked.”

For the following entries:

Money given per hour worked = $10

Number of hours worked per week = 5 hours

Savings period = 1 year or 52 weeks

(The duration of the saving is a constant in this code, the number of repetitions in the outer loop)


Coding window that show different variables; Amount earned per hour worked: ten. Hours per week: 5. Amount saved: 2600.

A nested loop can be used to demonstrate the multiplicative effect of multiple numbers; for example, 52 weeks × (5 hours per week × $10 per hour) or 52 × (5 × 10). In this code hours worked is constant from week to week. Students can alter the code where the hours are entered as well as the number of weeks and the earnings per hour.

Sample Code

Code Result (Output)
Image Blocks of code: Events block stating “start on when green flag is clicked”. Sensing block stating ”ask ‘how much money do you earn per hour of work?’ and wait”. Variables block stating “set amount earned per hour worked to” Motions block “answer”.” Sensing blocks “how many work weeks would you like to declare?’ and wait”. Variables block stating “numbers of work weeks to” motions block “answer”. Control block stating “repeat” variable block “number of work weeks”. Inside 7 nested blocks. Variables block stating “set week to ‘1’.” Motions block stating “ask how many hours did you work week’ join” variables block stating “week and wait”. Variable block stating “set hours to” motions block stating “answer”. Variable block stating “set weekly pay to ‘0’.” Control block stating “repeat” variable block stating “hours”.” Inside 2 nested blocks. Variable block stating “change weekly pay by amount earned per hour worked.” Variable block stating “change amount saved by amount earned per hour worked.” List block stating “add” variables block stating “weekly pay” list block stating “to weekly salary”.” Variables block stating “change week by ‘1’.” Variables block stating “amount earned per hour worked to ‘0’.”

For the following entries:

Money given per hour worked = $10

Number of weeks worked = 4

Hours worked per week = 2, 4, 3, 4

Savings period = 1 year or 52 weeks


Image Coding window that show different variables; Amount earned per hour worked: ten. Average pay per week: 32.5. Duration of saving (weeks): 52. Estimation of savings: 1690.

Note: The section of the code that resets all variables to zero, at each run, has been omitted from the example to simplify it. This pattern, which should be at the very beginning of the code, would look like this:

Image Blocks of code: Variables block stating “set money earned per hour worked to ‘0’.” Variables block stating “number of weeks worked to ‘0’.” Variables block stating“hours to ‘0’.” Variables block stating “Amount saved to ‘0’.” List block stating “delete all of weekly salary.” Variables block stating “Average weekly to ‘0’.” Variable block stating “Duration of savings (weeks) to ‘0’.” Variable block stating “estimation of the value of the saving to ‘0’.”