KEMBAR78
IGCSE in Computer Science Specification | PDF | Subroutine | Data Type
0% found this document useful (0 votes)
143 views7 pages

IGCSE in Computer Science Specification

The document describes a pseudocode command set including data types, constants, variables, arrays, selection, repetition, input/output, file handling, and subprograms. The pseudocode is intended for use in exam questions to provide clarity and consistency.

Uploaded by

fatimatumbi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
143 views7 pages

IGCSE in Computer Science Specification

The document describes a pseudocode command set including data types, constants, variables, arrays, selection, repetition, input/output, file handling, and subprograms. The pseudocode is intended for use in exam questions to provide clarity and consistency.

Uploaded by

fatimatumbi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Appendix 5: Pseudocode command set

Questions in the written examination that involve code will use this pseudocode for clarity
and consistency. However, students may answer questions using any valid method.

Data types
INTEGER
REAL
BOOLEAN
CHARACTER

Type coercion
Type coercion is automatic if indicated by context. For example 3 + 8.25 = 11.25
(integer + real = real)
Mixed mode arithmetic is coerced like this:

INTEGER REAL
INTEGER INTEGER REAL
REAL REAL REAL

Coercion can be made explicit. For example, RECEIVE age FROM (INTEGER) KEYBOARD
assumes that the input from the keyboard is interpreted as an INTEGER, not a STRING.

Constants
The value of constants can only ever be set once. They are identified by the keyword
CONST. Two examples of using a constant are shown.
CONST REAL PI
SET PI TO 3.14159
SET circumference TO radius * PI * 2

Data structures
ARRAY
STRING
Indices start at zero (0) for all data structures.
All data structures have an append operator, indicated by &.
Using & with a STRING and a non-STRING will coerce to STRING. For example, SEND ‘Fred’
& age TO DISPLAY, will display a single STRING of ‘Fred18’.

Pearson Edexcel International GCSE in Computer Science – Specification 37


Issue 1 – November 2016 © Pearson Education Limited 2016
Identifiers
Identifiers are sequences of letters, digits and ‘_’, starting with a letter, for example:
MyValue, myValue, My_Value, Counter2

Functions
LENGTH()
For data structures consisting of an array or string.
RANDOM(n)
This generates a random number from 0 to n.

Comments
Comments are indicated by the # symbol, followed by any text.
A comment can be on a line by itself or at the end of a line.

Devices
Use of KEYBOARD and DISPLAY are suitable for input and output.
Additional devices may be required, but their function will be obvious from the context. For
example, CARD_READER and MOTOR are two such devices.

Notes
In the following pseudocode, the < > indicates where expressions or values need to be
supplied. The < > symbols are not part of the pseudocode.

38 Pearson Edexcel International GCSE in Computer Science – Specification


Issue 1 – November 2016 © Pearson Education Limited 2016
Variables and arrays

Syntax Explanation of syntax Example

SET Variable TO <value> Assigns a value to a SET Counter TO 0


variable. SET MyString TO ‘Hello world’

SET Variable TO <expression> Computes the value of an SET Sum TO Score + 10


expression and assigns to SET Size to LENGTH(Word)
a variable.

SET Array[index] TO <value> Assigns a value to an SET ArrayClass[1] TO ‘Ann’


element of a SET ArrayMarks[3]TO 56
one-dimensional array.

SET Array TO [<value>, …] Initialises a SET ArrayValues TO [1, 2, 3, 4, 5]


one-dimensional array with
a set of values.

SET Array [RowIndex, Assigns a value to an SET ArrayClassMarks[2,4] TO 92


ColumnIndex] TO <value> element of a
two-dimensional array.

Selection

Syntax Explanation of syntax Example

IF <expression> THEN If <expression> is true IF Answer = 10 THEN


<command> then command is SET Score TO Score + 1
END IF executed. END IF

IF <expression> THEN If <expression> is true IF Answer = ‘correct’ THEN


<command> then first SEND ‘Well done’ TO DISPLAY
ELSE <command> is executed, ELSE
<command> otherwise second SEND ‘Try again’ TO DISPLAY
END IF <command> is executed. END IF

Pearson Edexcel International GCSE in Computer Science – Specification 39


Issue 1 – November 2016 © Pearson Education Limited 2016
Repetition

Syntax Explanation of syntax Example

WHILE <condition> DO Pre-conditioned loop. WHILE Flag = 0 DO


<command> Executes SEND ‘All well’ TO DISPLAY
END WHILE END WHILE
<command> whilst
<condition> is true.

REPEAT Post-conditioned loop. REPEAT


<command> Executes SET Go TO Go + 1
UNTIL <expression> UNTIL Go = 10
<command> until
<condition> is true. The
loop must execute at least
once.

REPEAT <expression> TIMES Count controlled loop. The REPEAT 100-Number TIMES
<command> number of times SEND ‘*’ TO DISPLAY
END REPEAT <command> is executed is END REPEAT
determined by the
expression.

FOR <id> FROM <expression> Count controlled loop. FOR Index FROM 1 TO 10 DO
TO Executes SEND ArrayNumbers[Index] TO
<expression> DO DISPLAY
<command> a fixed
<command> END FOR
number of times.
END FOR

FOR <id> FROM <expression> Count controlled loop using FOR Index FROM 1 TO 500 STEP
TO a step. 25 DO
<expression> STEP SEND Index TO DISPLAY
<expression> DO END FOR
<command>
END FOR

FOR EACH <id> FROM Count controlled loop. SET WordsArray TO [‘The’, ‘Sky’,
<expression> DO Executes for each element ‘is’, ‘grey’]
<command> of an array. SET Sentence to ‘‘
END FOREACH FOR EACH Word FROM
WordsUArray DO
SET Sentence TO Sentence &
Word & ‘ ‘
END FOREACH

40 Pearson Edexcel International GCSE in Computer Science – Specification


Issue 1 – November 2016 © Pearson Education Limited 2016
Input/output

Syntax Explanation of syntax Example

SEND <expression> TO Sends output to the SEND ‘Have a good day.’ TO


DISPLAY screen. DISPLAY

RECEIVE <identifier> FROM Reads input of specified RECEIVE Name FROM (STRING)
(type) type. KEYBOARD
<device>
RECEIVE LengthOfJourney FROM
(INTEGER) CARD_READER
RECEIVE YesNo FROM
(CHARACTER) CARD_READER

File handling

Syntax Explanation of syntax Example

READ <File> <record> Reads in a record from a READ MyFile.doc Record


<file> and assigns to a
<variable>.
Each READ statement
reads a record from the
file.

WRITE <File> <record> Writes a record to a file. WRITE MyFile.doc Answer1,


Answer2, ‘xyz 01’
Each WRITE statement
writes a record to the file.

Subprograms

Syntax Explanation of syntax Example

PROCEDURE <id> Defines a procedure. PROCEDURE CalculateAverage


(<parameter>, …) (Mark1, Mark2, Mark3)
BEGIN PROCEDURE BEGIN PROCEDURE
<command> SET Avg to (Mark1 + Mark2 +
END PROCEDURE Mark3)/3
END PROCEDURE

Pearson Edexcel International GCSE in Computer Science – Specification 41


Issue 1 – November 2016 © Pearson Education Limited 2016
Subprograms

Syntax Explanation of syntax Example

FUNCTION <id> Defines a function. FUNCTION AddMarks (Mark1,


(<parameter>, …) Mark2, Mark3)
BEGIN FUNCTION BEGIN FUNCTION
<command> SET Total to (Mark1 + Mark2 +
RETURN <expression> Mark3)/3
END FUNCTION RETURN Total
END FUNCTION

<id> (<parameter>, …) Calls a procedure or a Add (FirstMark, SecondMark)


function.

42 Pearson Edexcel International GCSE in Computer Science – Specification


Issue 1 – November 2016 © Pearson Education Limited 2016
Arithmetic operators

Symbol Description
+ Add
- Subtract
/ Divide
* Multiply
^ Exponent
MOD Modulo
DIV Integer division

Relational operators
Symbol Description
= equal to
<> not equal to
> greater than
>= greater than or equal to
< less than
<= less than or equal to

Logical operators

Symbol Description
AND Returns true if both
conditions are true.
OR Returns true if any of the
conditions are true.
NOT Reverses the outcome of
the expression; true
becomes false, false
becomes true.

Pearson Edexcel International GCSE in Computer Science – Specification 43


Issue 1 – November 2016 © Pearson Education Limited 2016

You might also like