Types and variables
INT, REAL, STRING and BOOLEAN, variables, constants and initial values.
The four basic types
| Type | Values | Example |
|---|---|---|
INT | Whole numbers | 42, -7 |
REAL | Decimal numbers | 3.14, 2.0 |
STRING | Text | "Hello" or 'Hello' |
BOOLEAN | Truth values | True, False |
A real number always has digits on both sides of the point: write 2.0, not 2. or .5. When you display a REAL, it appears in its shortest form, the same in every language: 2.0, 3.5, 12.56636.
Variables
variable count : INTvariable price : REAL := 9.99variable name : STRINGvariable done : BOOLEAN := False
:= gives an initial value. Without it, give the variable a value with <- before reading it.
Assignment
<- stores a value in a variable:
count <- 0count <- count + 1
The value must match the type of the variable. You can store an INT in a REAL, but not the opposite: count <- 2.5 is an error, because count is an INT.
Constants
A constant has a value that never changes. Give it a type and a value with =.
Algorithm Circleversion '1.0'language Cconstant PI : REAL = 3.14159variable radius : REALvariable area : REALbeginradius <- 2.0area <- PI * radius * radiuswrite("Area: ", area, "\n")endend algorithm
Output
Area: 12.56636circle.aml on GitHubTry itSoonTrying to change PI later, or to read a value into it, is refused by the checker.