5 coding concepts you can learn in Scratch
Scratch is one of the most prolific coding languages used by Dojos around the world. It is great for young people learning to code as it is so visual. It also provides “quick-wins” that motivate and empower young people to continue coding.
Scratch has been developed to teach the logic of coding, without young people worrying about typing or remembering names and syntax. Below are 5 coding concepts you can highlight in Scratch, and projects to help you do so. This can be useful when moving on from Scratch to a text-based language as they will already have an understanding of the coding concepts involved.
Sequences are the logical structure of an algorithm or a program. They are the instructions or steps in order. Your program can contain any number of instructions but each instruction must be run in the order presented. Scratch teaches this as the scripts or groups of code blocks run in order from top to bottom.
Repetition and Iteration (loops)
Repetition is the repeating of a series of instructions. Whereas iteration is repeating of instructions until a certain condition is met. These are both types of loops. Blocks that are used for repetition and iteration in Scratch are “Forever”, “repeat” and “repeat until”.
Repeat, Forever and repeat until blocks also help young people understand what code is within a loop and what is not included in a loop, in Scratch but also in text-based languages. In Scratch the repeat block wraps around other code blocks within a loop. You can use this to help explain how indentation works in languages like Python. This helps young people see that the code needs to be indented to the right to run within a loop.
Data (Variables and Lists)
Variables store specific information. You can use the variables tab in Scratch to create your own, but there are also pre-made variables built into Scratch. Common variables include timer, answer and coordinates. These are built into Scratch. While score and name are variables you can use the variable block to create.
For example “coordinates” store the location information of where the sprite is on the stage. You can use this to start the sprite off in a certain location, or to move a sprite to a specific place on the stage very easily.
Lists are similar to variables, but lists store multiple pieces of information at once. You can use the “Score” variable to store a single score someone achieved playing a Scratch game. However, to record multiple scores, to see what the highest scores of multiple gameplays were in order, you would need to use a list. Lists contain numbers paired with items(ie. Individual variables, which can also be numbers). The number of variables stored in a list are numbered to allow you to control them with other Scratch blocks. You can also use lists as an “inventory” or “bagpacks” in open-world games where the sprite picks up items to be used at a later time in the game.
Did you know? You can import a .txt or .csv file into a list in Scratch. When importing .txt files, each line represents each item in the list. With CSV files only one chosen column will be imported.
Selection / Conditional statements
These are a set of rules performed if a certain condition is met. Similar to iteration and the “repeat until” block in Scratch, this is checking “if” certain conditions are being met and then running the related code if they are. Blocks that “check for a condition” in Scratch are: if then, if else, repeat until.
Procedures are a set of instructions that performs a task. These are really useful for grouping instructions and reusing code. Say you have a large sequence of blocks that you want to repeat multiple times in your Scratch project, such as if you want a number of sprites to react the same way to something or you want the same end screen triggered on a multi-level game. Instead of duplicating the same code multiple times, you can use the “make” block, and define that sequence of blocks as a certain term or label, and then use that single block to represent the larger sequence of blocks.
Projects that teach these concepts
- Rock Band = sequencing and events
- Lost in space / Butterfly garden = loops
- Ghostbusters = variables
- Turtle tracker = lists
- Chat Bot = selection / conditionals
Boat Race = consolidation of the above.
- Falling stars = procedures