We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Variables and arrays
Syntax
Explanation of syntax
Example
SET Variable TO
Assigns a value to a variable.
‘SET Counter TO 0
‘SET MyString TO ‘Hello world’
SET Variable TO
SET Arrayfindex] TO
‘Computes the value of an
‘expression and assigns to
variable.
Assigns a value to an element
‘of aone-dimensional array.
SET Sum TO Score + 10
SET Size to LENGTH(Word)
SET ArrayClass{1] TO‘Ann’
SET ArrayMarks[3]TO 56
SET Array TO [, ..]
Initialises a one-dimensional
SET ArrayValues TO [1, 2, 3, 4, 5]
array with a set of values.
SET Array [Rowindex, Assigns a value to an element
Columnindex] TO ‘of atwo dimensional array. SET ArrayClassMarks|2.4] TO 92
Selection
Syntax Explanation of syntax Example
IF THEN ions i IF Answer = 10 THEN
If is true then SET Score TO Score +1
ENDIE command is executed. ENDIF
IF THEN IF Answer =‘correct’ THEN.
If is true then first t
: seonmane> ccompnands executed, SEN Well doneTO DISPLAY
‘otherwise second
SEND Try again’ TO DISPLAY
ENDIF is executed. ENDIFRepetition
Syntax Explanation of syntax Example
WHILE DO Pre-conditioned loop. Executes | WHILE Flag = 0 DO
command? wi SEND ‘All well’TO DISPLAY
END WHILE is true. END WHILE
Post-conditioned loop.
REPEAT Executes REPEAT
until SET GoTO Go+1
UNTIL istrue. The loop must execute UNTILGo = 10
at least once.
REPEAT Times | Count somolled loop. The rnd, REPEAT 100-Number TIMES
number of times FROM
TO
DO
END FOR
Count controlled loop.
Executes:
a fixed number of
times.
FOR Index FROM 1 TO 10 DO
SEND ArrayNumbers[index}
TO DISPLAY
END FOR
FOR FROM
TO
STEP
DO
Count controlled loop using
astep.
FOR Index FROM 1 TO S00 STEP.
25D0
SEND Index TO DISPLAY
END FOR
END FOR
SET WordsArray TO [The, ‘Sky;
‘is, grey]
FOREACH FROM Count controlled loo SET Sentence to”
DO bree P. FOR EACH Word FROM
utes for each clement of
eee WordsUArray DO
END FOREACH y- SET Sentence TO Sentence &
Word &'*
END FOREACHsyntax
Explanation of syntax
Example
SEND TO DISPLAY
Sends output to the screen.
SEND ‘Have a good day:TO
DISPLAY
RECEIVE FROM
RECEIVE Name FROM (STRING)
KEYBOARD
, , RECEIVE LengthOfJourney
(ope Reads input of specified type. From (INTEGER) CARD_READER
RECEIVE YesNo FROM
(CHARACTER) CARD_READER
File handling
Syntax Explanation of syntax Example
Reads in a record from a
, and assigns to a . i
READ and assigns to a
Writes a record to a file.
Each WRITE statement writes a
record to the file.
WRITE Myfile.doc Answerl,
Answer?, ‘xyz 01°File handling
Syntax Explanation of syntax Example
Reads in a record from a
, and assigns to @ . .
READ Ae eed coteenteicg | READ MyFiledoc Record
record from the file.
Writes a record to a file.
WRITE Each WRITE statement writes a ware eae Answer,
record to the file, at
Subprograms
Syntax Explanation of syntax Example
PROCEDURE cid> PROCEDURE CalculateAverage
(Mark, Mark2, Mark3)
(parameter) BEGIN PROCEDURE
BEGIN PROCEDURE Defines a procedure. SET Avg fo (Markt + Mark2-+
Marky
END PROCEDURE END PROCEDURE
FUNCTION cid FUNCTION AddMarks (Mark,
(cnarnaters ‘Mark2, Mark3)
BEGIN FUNCTION BEGIN FUNCTION
Defines a function. SET Total to (Mark1 + Mark2 +
Markey
RETURN
END FUNCTION RETURN Total
END FUNCTION
(, ...)
alls a procedure or a
function.
Add (FirstMark, SecondMark)