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: Repetitive Events Related to Daily Life


  • Begin a mathematical discussion with students related to repeated events 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).

Suite ABCD 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. This prepares them to explore the nested structure of the loop within the loop.
  • Then ask students the following question: How could you extend the following?
  • Form small, heterogeneous groups, including students who have observed the pattern in different ways. Invite students to discuss with other group members. Listen to their reasoning.
  • Ask students to create a pseudo code for a robot that must deal cards according to a pattern.

Example of Pseudocode

When the code is executed :

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 then repeat the activity by creating a pattern using cards and asking a partner to create the pseudo code for the robot that will extend the pattern.

Activity 2: Financial Literacy and Nested Events


A fourth-grade student does extra household chores for her parents to earn spending money. Her parents pay her an amount per hour of work, which she receives on Friday of each week. She decides to save the money earned.

Using nested events, create code that will predict the value of one's savings after a certain amount of time.

This situation is open-ended "by design" to encourage students to use variables in creating 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.

Using a nested loop allows the student to see the multiplicative effect of the loop within the loop. The operation represented here would effectively be 52 weeks × (5 hours per week × $10 per hour) or

52 × (5 × 10). This code is limited because the hours worked remain constant from week to week. An extension of this activity could be to add elements to the code to make it more adaptable. The student, for example, could enter his or her hours in a list, and the code could take the average of the entries to make predictions.

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’.”