Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Variables [3/14]

A variable name is a primary expression, therefore it can be used as a part of a complex expression.
[Run the program]

A println statement without any arguments has the effect of advancing the text output to a new line.

A value of a variable can be changed. In this program, the value of variable c is changed by the statement of assignment in the next-to-last statement of this program.
[Run the program]

Exercises:

1. At the end of the source code, add a statement that changes value of the variable c once again, this time to expression 5/2.

Solution

c = 5/2;

2. Print out the value of variable c.

Solution

println c;

3. Introduce a new variable named oneThird at the end of the source code, and set its value to result of expression 1/3.

Solution

#num oneThird = 1/3;

4. Print out the value of variable oneThird.

Observe that the printed value is only approximately correct. As computers are finite machines, they cannot store the exact result of expression 1/3 as a decimal number, because it needs an infinite number of digits. Type num uses the decimal number system to store values.

Loading...