Rule for keywords
Must be capital
How to show comments
//
State 5 data types + how are they written/delimited
Identifiers
Names given to variables, constants, procedures & functions. Letters and digits only.
Declaration
States/declares data type of variable (by its identifier).
DECLARE [identifier] : [data type]
Constant
A value in a program that never changes.
Assignment operator
<— (arrow)
Format: identifier <— value
Array + declaration (1d & 2d)
Fixed-length structure of elements of identical data types, accessible using index numbers. E.g. ArrayName[Index] <— 23
1d: DECLARE identifier : ARRAY[1:30] OF data type
2d: DECLARE identifier : ARRAY[1:30, 1:30] OF data type
Input and output operations
INPUT identifier
OUTPUT values or “string”
Not standard arithmetic operations
^ = to the power of
DIV(x,y) = returns quotient/whole number left after division of x by y
MOD(x,y) = returns remainder after division of x by y
Not equal to symbol
<>
4 string operations
Round & random library routines
Selection
IF condition:
THEN
statements
ELSE
statements
ENDIF
(THEN can be placed in same line as IF, and ELSE is not needed. ELIF can be used)
State & explain 3 types of loops
Variable
Data structure used to store value in a program that can change/be overwritten any number of times.
For loop structure
FOR identifier <— value1 to value2:
statements
NEXT identifier
Repeat loop structure
REPEAT
statements
UNTIL condition
While loop structure
WHILE condition DO
statements
ENDWHILE
Subroutines
Functions & procedures. Blocks of associated code/subroutines (separated piece of named code that performs a particular task) that can be called multiple times.
Parameter + purpose
Value that adds extra information to a subroutine to adjust its behavior.
Alows procedure to be reused with different data/values.
Procedure structure
Does not return value.
PROCEDURE identifier (parameter:datatype)
statements
ENDPROCEDURE
To call:
CALL identifier
Function
= additional parameters can be added, in order to specify what variables the function is operating on
Return a single value to the point at which they are called.
FUNCTION identifier (p) RETURNS data type
RETURN statements
ENDFUNCTION
Cannot be called, would use it in output/print statement
p = possible parameters
File handling
OPENFILE “file identifier.txt” FOR file mode
statement
CLOSEFILE ‘file identifier.txt’
File mode can be READ or WRITE (new file will be created & any existing data in the file will be lost)
Statement can be:
1. READFILE ‘identifier.txt’, variable - data from file will be read from text file into variable
2. WRITEFILE ‘identifier.txt’, variable - data from variable is written into file.