C3.2 Read and alter existing code, including code that involves sequential, concurrent, repeating, and nested events, and describe how changes to the code affect the outcomes.

Skill: Reading a Code


Code reading involves interpreting blocks or commands to deduce the meaning of the code. This allows the student to make predictions related to the behaviour of the code. Code reading is also an important part of debugging, the identification and correction of errors in the code. By reading the code, it is possible for the student to identify the reason(s) why it is not working. Note that this skill does not correspond to the computer reading the code, but rather to the student reading the code to verify it.

Students can do code reading to identify the pattern of a sequence, as in the following code:

Image Blocks of code: Events block stating “start on when green flag is clicked”. Pen extension stating “erase all”. Motions blocks stating “go to x:’-200’ y: ‘-160’.” Control blocks stating “wait ‘1’ seconds”. Pen extension stating “stamp”. Motions blocks stating “change y by ‘20’.” Control blocks stating “wait ‘1’ seconds”. Pen extension stating “stamp”. Motions blocks stating “change y by ‘20’.” Control blocks stating “wait ‘1’ seconds”. Pen extension stating “stamp”. Motions blocks stating “change y by ‘20’.” Control blocks stating “wait ‘1’ seconds”. Pen extension stating “stamp”. Motions blocks stating “change y by ‘20’.” Control blocks stating “wait ‘1’ seconds”. Pen extension stating “stamp”.

Students may notice that the pattern looks like this:

(Move token), (Pause for one second), (Stamp)

Skill: Modifying Code


The culture of computer programming is one of sharing. Many programs are created based on existing code. Modifying code allows the student to start from an existing and functional code sequence in order to build something new. Modifying code can also be done to simplify it or to demonstrate that there is more than one way to represent the same situation using code. If necessary, the student can also modify erroneous code to make it functional, a process called debugging.

Using the same code as in the previous example, the student could identify blocks that simplify the code by isolating the pattern. The resulting code might look like this:

Image Blocks of code: Events block stating “start on when green flag is clicked”. Looks block stating “show”. Pen extension stating “erase all”. Motions blocks stating “go to x:’-200’ y: ‘-160’.” Controls blocking “repeat 5”. Inside 3 nested blocks. Control blocks stating “wait ‘1’ seconds”. Pen extension stating “stamp”. Motions blocks stating “change y by ‘20’.” Looks block stating “hide”.

In this case, the student would have chosen to use a loop to isolate the pattern and simplify the code.

Skill: Describing the Impact of Changes on Code


Trial and error learning is an important part of creating code sequences. However, it is important that the student be able to justify their choices of modifications to an existing code by making predictions about the effect of the changes on the behaviour of the code.

During pattern creation using geometric properties, the student has several variables to play with without making the code non-functional. In the following code:

Image Blocks of code: Events block stating “start on when green flag is clicked”. Pen extension stating “erase all”. Pen extension stating “pen down”. Motions block stating “go to x: ‘0’ y” ‘0’”. Control block stating “repeat 10”. Inside 2 nested blocks. Control blocks stating “repeat 2”. Inside 4 nested blocks. Motions block stating ‘move 100’ steps”. Motions block stating “turn left ‘90’ degrees”. Motions block stating ‘move 150’ steps”. Motions block stating “turn left ‘90’ degrees”. Motions block stating “turn right ‘15’ degrees”. Pen extension stating “pen up”.

The following pattern is created:

Image This is a series of ten rectangles. The starting point of each rectangle is the same. The lower left corner of each rectangle is joined to the center point. This formation gives the appearance of a flower.

The following questions could be asked of the student:

  • What changes will be needed to create triangles instead of rectangles?
  • What happens if the number of degrees of rotation increases towards the end of the code?
  • Is the "raise the pen" block necessary? What is its role?
  • How will more repetitions of the outer loop change the appearance of the pattern?