SHOP

PLAY

CREATE

8

Learn how to use loops

Min. Age: 5+ Mother and son; age icon Duration: 20 min. Mother and son; age icon

Video Example:

Material required: Download material .pdf

Play

1

What is our goal?

The goal is to write a program that eats all the slices of a banana from a plate.

2

How do we play?

If played solo, the player will write and execute the code. If played with two players, one player writes and reads the code, while the other player performs the actions.

3

Slice

Place 3-5 slices of banana on a plate.

Five banana slices on a plate
4

Let's answer a few questions first

1

How many banana slices do you want your program to eat?

The answer to this question determines the values in your initialization assignment block.

Initialization assignment. k variable is initialized to 5 There are 5 slices. k = 5;
2

What steps do you take to eat a single slice of banana?

Write each step on a blank tile. Each of this steps is a function.

Blank tile with 'chew()' function call on it
Blank tile
Blank tile

Once written, place each function to eat a slice into a code block. This will form the body of your loop

Function calls conforming a loop body
Monkey asking: who eats a banana with a fork?
3

How long will you keep eating slices?

Banana slices decreasing on a plate.

The answer to this question will help you determine the loop condition.

Loop condition block. k greater than 0 The program will eat slices while there are more than 0 slices on the plate. While k > 0, the program will keep eating slices.

Use the Not equal to operator operator (not equal to ≠), for children who do not yet understand the 'greater than' operator.

4

Arrange the blocks as follows:

Banana loop program done in blocks
Are you ready to loop?
5

What do I do during my turn?

1

Initialize 'k' with the number of slices on the plate:

For loop initialization assignment. k variable is initialized to 5 k = 5;
2

Enter the condition loop. Is the value of 'k' greater than 0?

For loop condition. Is k greater than 0 ?

If TRUE follow the arrows to the loop body.

3

Once in the loop body, call the functions to eat a banana slice.

Function calls conforming a loop body Fork a slice, move fork to mouth, then chew.
4

Follow the direction arrows to enter the decrement assignment. Update the number of banana slices in the plate.

Decrement the value of 'k' using a decrement assignment.

Then re-enter the loop condition. Iterate through the loop while the condition evaluates to TRUE.

6

When does the game end?

The game ends when the loop condition 'k > 0' is no longer met, that is, when there are 0 slices left to eat on the plate.

Loop condition is no more met. Exiting loop and ending the program.

When 'k' is not greater than 0, exit the loop and END the program.


Puzzles:

Read 1

6+ years
Blurred image of a puzzle to create a loop using blocks
Blurred image of a program of a loop using blocks

Write2

7+ years
Blurred image of a puzzle text to write a program with loops

Write3

8+ years
Blurred image of a puzzle text to write a program with loops

Debug4

7+ years
Blurred image of a puzzle text to write a program with loops

Write5

12+ years
Blurred image of a puzzle to write a banana loop game

Read6

12+ years
Blurred image of a puzzle to draw figures using a loop

Write7

12+ years
Blurred image of a puzzle about coding loops

Debug8

12+ years
Blurred image of a puzzle about debugging and fixing a loop in a program