C3.2 Read and modify given codes, including codes with sequential events and simultaneous events, and describe the impact of these changes on outcomes in a variety of contexts.

Skill: Reading Code


Reading code involves interpreting blocks or commands to make predictions about its outcome. Reading code is also an important part of debugging to identify and correct errors of why the code is not working or getting the desired outcome.

For example, the student could be presented with code for two sprites that are having a "race". The student would first have to predict which sprite would win the race. Here is an example of code:


At first glance, one of the two codes appears to have more moves, but upon closer reading of the code, it is possible to see that some blocks represent more than one move. The student will need to understand this element of the code syntax first in order to make their prediction.

Skill: Altering Code


One of the reasons to alter code is to save time by not starting from scratch but to use existing code to build something new. Altering code can also be done to make the code more efficient and reduce runtime or to demonstrate that there is more than on way to use code to represent a situation. Another reason to alter code is to fix errors and make it functional, a process called debugging.

Students could alter the two butterflies code above so that both butterflies finish the race with a tie. This does not necessarily mean that both butterflies will make the same movements, but rather that the number of movements of one butterfly will be reduced or the "wait" block will be used to give the slower butterfly a chance to catch up to the other butterfly.

Skill: Describing the Impact of Altering Code


Understanding the sequencing of events that will occur based on the code is important for altering code so that one can make predictions about how the changes will affect the outcome.

Using the recording features of coding program allows students to add audio blocks describing their choices during an activity when students must alter the provided block to achieve a specific goal.

Knowledge: Simultaneous Events


Simultaneous events are events that occur at the same time. Note, however, that events do not have to be identical to be considered simultaneous.

A common example of the use of simultaneous events is diagonal movement. Most block coding and robotics programs allow movement in four directions (for example, up, down, left, right), but a diagonal move requires both a horizontal and a vertical move at the same time.

Let's take, for example, the following imaginary city:

The student could be given the code below to predict the final location of the sprite if the initial location is well defined. In this example, the sprite would begin its journey at the police station and end at the school.


This code contains two simultaneous starting situations, the receipt of the message which is symbolized by the orange envelope. The student could then have the task of modifying the code so that the sprite goes from the hospital to the store or makes any other diagonal movement.