Variables

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.

Drop down menu

When you click the drop down symbol (small triangle) for a variable, the following menu appears:

Bild1_e.PNG

The menu offers the following options.

Blocks

Set

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:

Bild2_e.PNG

Call

The call block delivers a variable saved in a variable without changing it:

Bild3.PNG

It is possible to write a program containing a call block without a relevant set block, but this is a bad idea.

Change

The change block inserts a number for a variable.

Bild4_e.PNG

The change block is an abbreviation for the following construct:

Bild5_e.PNG

Example

Look at the following example code:

Bild6_e.PNG

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.”


Revision #1
Created 21 February 2022 15:50:52 by Admin
Updated 9 January 2023 10:36:46 by Admin