Variables

Variables are used to store data. It is a named storage location in the computer memory.
To use a variable in Alice we need to create it first. The creation of a variable is simple. Just drag the variable tile from the control area to the code area and provide a meaningful name, value type and initial value.

Example Using Variable
In this example we will use two variables to store the heights of theboy and thegirl and then display the values stored in the variables making use of the say procedure and mathematical function we have learned earlier.
 The steps involved:
1. Create a variable height_boy, value type Decimal Number and Initial value 0.25
2. Create a variable height_girl, value type Decimal Number and Initial value 0.25
3. Drag and drop the getHeight functions to the respective value places
4. Use the say procedure to display the values



 

1 comment: