9.3 Variable Assignment

9.3.1 Synopsis

variable_name = expression;
variable_name_1 = variable_name_2 = expression;

9.3.2 Description

With the former syntax, if no variable called variable_name exists it is created and expression is stored within. If a variable with the same name already exists, its value is replaced by expression. The second form is similar, but allows to define and assign a number of variables in a single statement.

Expression can be any valid expression:

9.3.3 Example

quote1 = "Wild animals never kill for sport.";
quote2 = quote1;
quote3 = quote4 = quote1;

The first line creates a variable called quote1 whose value is "Wild animals never kill for sport.". Then, we define other variables and assign them the same value. These are the variables and their values:

quote1

Wild animals never kill for sport.

quote2

Wild animals never kill for sport.

quote3

Wild animals never kill for sport.

quote4

Wild animals never kill for sport.

Now, let's replace the last three variables' values with new ones:

quote2 = "Man is the only one to whom the torture and death";
quote3 = "of his fellow creatures is amusing in itself.";
quote4 = "-- Froude";

These are the variables and their new values:

quote1

Wild animals never kill for sport.

quote2

Man is the only one to whom the torture and death

quote3

of his fellow creatures is amusing in itself.

quote4

- Froude

This manual can be downloaded from http://www.g-cows.org/.