6.2.1 Variables

View

In computer science, variables are a named location where information can be stored. A variable is a container that can hold one piece of information at a time, like a word or a number. Being able to hold this value allows us to refer to it and manipulate it at different places in a program.

Figure 148: The interface of the Variables block

 

Scratch has provided an easy way to create variables. A set of blocks is provided to manipulate variables that you created. In Scratch and many other programming languages, there are two ways to use a variable. You can store information in it, or you can read what is already there.

The Variables block is divided into 2 sections: the stack block and the reporter’s block. Initially the reporter’s block has 1 item while the stack block has 4 items (Figure 148).

 

 

Figure 149: Reporter and Stack block

Before using variables in a Scratch project, let us first create our own variables.

Last modified: Friday, 22 October 2021, 11:20 AM