1 of 14

Lesson 6: Loop On

Challenge focus: 26 - 30

Coding Concepts: The syntax of the simple times loop

Coding Adventure Part I

Key stage II

Class IV

2 of 14

Lesson Overview

Challenge Range

Coding Concepts

Sub Concepts

Resources

26 - 30

Loops

  • The syntax of the simple loop(times)

Lesson Plan 27

Loop On

Coding Adventure Part I

Key stage II

Class IV

3 of 14

Lesson Objectives

  • Explain why using loops in programming is more efficient.
  • Explain the importance of using indentation correctly.
  • Complete challenges 26 - 30

Coding Adventure Part I

Key stage II

Class IV

4 of 14

The syntax to define simple times loop

where :

  • n’ refers to the number of times the loop repeats.
  • Before “Your code here”, you have to maintain indentation(spacing).

1

n.times-> #loop header

2

………..#Your code here #loop body

indentation

Coding Adventure Part I

Key stage II

Class IV

5 of 14

The importance of the indentation

  • It improves code readability.
  • It is used to delimit blocks of code within it.
  • It determines the beginning and end of code blocks.

Coding Adventure Part I

Key stage II

Class IV

6 of 14

Demo 1

Write a code to collect all the bananas for the given challenge 26.

Coding Adventure Part I

Key stage II

Class IV

7 of 14

Demo 1 Solution

Loop body

Indentation

Loop repeats 3 times

Coding Adventure Part I

Key stage II

Class IV

8 of 14

Activity 1

Identify the bugs in the code given right side and rewrite the code to collect the bananas (unplugged activity).

Coding Adventure Part I

Key stage II

Class IV

9 of 14

Activity 1 Solution

No indentation

Used wrong function

1

#solution

2

4.times->

3

step 10

4

step -10

5

turn right

Coding Adventure Part I

Key stage II

Class IV

10 of 14

Activity 2

  • Log into your CodeMonkey account.
  • Open Coding Adventure Part 1
  • Complete challenges 28 to 30. Challenge 26 & 27 have already been demonstrated to you earlier.

Coding Adventure Part I

Key stage II

Class IV

11 of 14

Activity 2 solution

28

Coding Adventure Part I

Key stage II

Class IV

12 of 14

Activity 2 Solution

29

Coding Adventure Part I

Key stage II

Class IV

13 of 14

Activity 2 Solution

30

Coding Adventure Part I

Key stage II

Class IV

14 of 14

Key Points

  • A simple loop is a block of instructions that repeats a specific number of times.
  • A loop must have a loop header and a loop body part.
  • Indentation improves code readability.
  • Indentation is used to delimit blocks of code within it.
  • Indentation determines the beginning and end of code blocks.

Coding Adventure Part I

Key stage II

Class IV