Variables and data types#

Basic data types#

Data type

Description

Examples

INTEGER

A whole number

5, -267, 153489

REAL

A number with decimal point

3.142, 56.0, -0.75

CHAR

A single character enclosed in single quotes

'K', '#', '6'

STRING

Zero or more characters enclosed in double quotes

"Yes", "Hi, John"

BOOLEAN

The logical values TRUE and FALSE

TRUE, 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?

  1. myBestScore

  2. Name

  3. 1stClass

  4. cost_of_meal

  5. Print84

  6. A-1

  7. _1234

Exercise

For each of thee following variables, state whether they need to be of STRING, INTEGER or REAL type.

  1. Price

  2. NumberOfSiblings

  3. Name

Exercise

Predict what is printed when runs these statements.

X <- 5
Y <- 10
X <- Y
Y <- 5

OUTPUT X
OUTPUT Y