Pseudocode is CASE SENSITIVE. All keywords must be in uppercase.
Variables must be declared before they are used or assigned a value. Variables must be declared as a type.
DECLARE variable AS INTEGER
variable = 10
DECLARE name, surname AS STRING
name = "Tom"
surname = "Jones"
Arrays must be declared with a value indicating size. Only one array can be declared at a time.
DECLARE variable(10) AS INTEGER
Note that function declarations require a type for the return value to be declared.
For these exercises you will need to RETURN
a result.
FUNCTION adder(FIRST, SECOND) AS INTEGER
DECLARE THEANSWER AS INTEGER
THEANSWER = FIRST + SECOND
RETURN THEANSWER
END FUNCTION
Symbol | Meaning |
---|---|
== |
exactly equals |
!= |
does not equal |
+ |
addition or string concatenation |
- |
subtraction |
* |
multiplication |
/ |
division (float) |
MOD |
remainder (modulo) |
> |
greater than |
>= |
greater than or equal |
< |
less than |
<= |
less than or equal |
Symbol |
---|
NOT |
AND |
OR |
then
is optional. All if
statements must be on a
single line. You can also use end
instead of end if
IF NUM < 42 THEN
// something
END IF
IF NUM < 42 THEN
// something
ELSE
// something else
END IF
IF NUM < 42 THEN
// something
ELSE IF NUM > 55 THEN
// something else
ELSE
// more code
END IF
DECLARE NUM AS INTEGER
NUM = 0
WHILE NUM < 10
OUTPUT NUM
NUM = NUM + 2
END WHILE
// 0
// 2
// 4
// 6
// 8
FOR NUM = 0 TO 4 STEP 1
OUTPUT (5 - NUM)
END FOR
OUTPUT "Blastoff!"
// 5
// 4
// 3
// 2
// 1
// Blastoff!
DECLARE NUMS(3) AS INTEGER
NUMS[0]=42
NUMS[1]=13
NUMS[2]=78
OUTPUT NUMS[0] // 42
OUTPUT NUMS[2] // 78
NUMS[1] = 11 // NUMS is now [42, 11, 78]
User input can be obtained thus.
DECLARE name AS STRING
INPUT "What is your name?" --> name