Variables and data types
Contents
Variables and data types#
Basic data types#
Data type |
Description |
Examples |
|---|---|---|
|
A whole number |
5, -267, 153489 |
|
A number with decimal point |
3.142, 56.0, -0.75 |
|
A single character enclosed in single quotes |
|
|
Zero or more characters enclosed in double quotes |
|
|
The logical values TRUE and FALSE |
|
Variable declarations#
// DECLARE {identifier} : {data type}
DECLARE Counter : INTEGER
DECLARE TotalToPay : REAL
DECLARE GameOver : BOOLEAN
Assignments#
// {identifier} <- {value}
// Should declare variable first and then assign it
DECLARE Counter : INTEGER
Counter <- 0
Counter <- Counter + 1
OUTPUT Counter
Exercises#
Exercise
Which of the following are valid variable names?
myBestScore
Name
1stClass
cost_of_meal
Print84
A-1
_1234
Answer
2, 5
Exercise
For each of thee following variables, state whether they need
to be of STRING, INTEGER or REAL type.
Price
NumberOfSiblings
Name
Answer
REAL
INTEGER
STRING
Exercise
Predict what is printed when runs these statements.
X <- 5 Y <- 10 X <- Y Y <- 5 OUTPUT X OUTPUT Y