AlgoML
FR

Types and variables

INT, REAL, STRING and BOOLEAN, variables, constants and initial values.

The four basic types

TypeValuesExample
INTWhole numbers42, -7
REALDecimal numbers3.14, 2.0
STRINGText"Hello" or 'Hello'
BOOLEANTruth valuesTrue, 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 : INT
variable price : REAL := 9.99
variable name : STRING
variable 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 <- 0
count <- 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 Circle
version '1.0'
language C
constant PI : REAL = 3.14159
variable radius : REAL
variable area : REAL
begin
radius <- 2.0
area <- PI * radius * radius
write("Area: ", area, "\n")
end
end algorithm
Output Area: 12.56636circle.aml on GitHubTry itSoon

Trying to change PI later, or to read a value into it, is refused by the checker.

Report a problem with this page