0% found this document useful (0 votes)
27 views3 pages

Pages From International Gcse in Computer Science - Spec PDF

The document provides a comprehensive overview of programming syntax related to variables, arrays, selection, repetition, input/output, file handling, and subprograms. It includes explanations and examples for each syntax type, demonstrating how to assign values, control program flow, handle input/output, and define procedures and functions. This serves as a guide for understanding basic programming concepts relevant to the Pearson Edexcel International GCSE in Computer Science.

Uploaded by

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

Pages From International Gcse in Computer Science - Spec PDF

The document provides a comprehensive overview of programming syntax related to variables, arrays, selection, repetition, input/output, file handling, and subprograms. It includes explanations and examples for each syntax type, demonstrating how to assign values, control program flow, handle input/output, and define procedures and functions. This serves as a guide for understanding basic programming concepts relevant to the Pearson Edexcel International GCSE in Computer Science.

Uploaded by

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

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

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.

Pearson Edexcel International GCSE in Computer Science – Specification 1


Issue 1 – November 2016 © Pearson Education Limited 2016
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

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

2 Pearson Edexcel International GCSE in Computer Science – Specification


Issue 1 – November 2016 © Pearson Education Limited 2016
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

Subprograms

Syntax Explanation of syntax Example

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


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

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


function.

Pearson Edexcel International GCSE in Computer Science – Specification 3


Issue 1 – November 2016 © Pearson Education Limited 2016

You might also like