We use the term variable as it is used in mathematics and other programming languages: a named value that can be changed (varied). Variables can be created in different ways.
- Some blocks like count with and for each use a variable and define its values. A traditional IT term for such variables is loop variables.
- User-defined functions (also called “procedures” can define inputs, which can be used to create variables that can only be used in this function. Such variables are traditionally referred to as “parameters” or “arguments.”
- Users can change variables at any time using the set block. These are traditionally called “global variables.” They can be used anywhere in the code of ROBO Pro Coding.
Drop down menu
When you click the drop down symbol (small triangle) for a variable, the following menu appears:
The menu offers the following options.
- display the names of all available variables defined in the program.
- “rename variable ...,” e.g. change the name of this variable wherever it appears in the program (choosing this option will open a query asking for the new name)
- “delete variable ...,” e.g. Delete all blocks that refer to this variable, wherever they are in the program.
The set block assigns a value to a variable, and creates the variable if it does not yet exist. For example, this is how to set the value for the variable age to 12:
The call block delivers a variable saved in a variable without changing it:
It is possible to write a program containing a call block without a relevant set block, but this is a bad idea.
The change block inserts a number for a variable.
The change block is an abbreviation for the following construct:
Look at the following example code:
The first row of blocks creates a variable named age and sets its initial value to the number 12. The second row of blocks calls up the value 12, adds 1 to it, and saves the total (13) in the variables. In the last line, the following message appears: “Congratulations! You are now 13.”