0% found this document useful (0 votes)
167 views7 pages

AQA Pseudocode Specification

AQA Pseudo code Specification
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)
167 views7 pages

AQA Pseudocode Specification

AQA Pseudo code Specification
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

AQA GCSE Computer Science

Pseudo Code Structure


Version 2

AQA GCSE Computer Science


Pseudo Code Structure

The pseudo code described below is a teaching aid for schools/colleges to assist in preparing their students for Unit 2 (examined component) of AQA’s GCSE Computer
Science. Schools/colleges are free to use any methods they feel appropriate for teaching algorithm design.

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

This document will be updated as required and the latest version will always be available on e-AQA. The version for use in the following summer exam will be published no later
than 1st September.

To register to use e-AQA, please visit extranet.aqa.org.uk/register

Updates will not usually be made during an academic year. If a revised version is published, AQA will inform schools/colleges.

Copyright © 2012 AQA and its licensors. All rights reserved.


The Assessment and Qualifications Alliance (AQA) is a company limited by guarantee registered in England and Wales (company number 3644723)
and a registered charity (registered charity number 1073334). Registered address: AQA, Devas Street, Manchester M15 6EX
Syntax Meaning Example
Variables and arrays
var ← exp Variable assignment: computes the value of exp a ← 3
and assigns this to var. In common with most b ← a + 16
pseudocode conventions types are inferred not c ← LEN(d)
declared.
var[iexp] ← exp One-dimensional array assignment. Indexing will arr[3] ← 5
start at 1, not 0.

var[iexp1][iexp2] ← exp Two-dimensional array assignment. arr[3][6] ← “hello”

# this assigns the value “hello” to # the


6th index of the array found
# at the 3rd index of arr.
var ← [exp1, exp2,…, expn] Array initialisation of n elements. myArr ← [34, 43, 11, 43, -3]

Copyright © 2012 AQA and its licensors. All rights reserved.


The Assessment and Qualifications Alliance (AQA) is a company limited by guarantee registered in England and Wales (company number 3644723)
and a registered charity (registered charity number 1073334). Registered address: AQA, Devas Street, Manchester M15 6EX
Syntax Meaning Example
Branching and Looping
IF bexp THEN Conditional branching. IF myVar < 15 THEN
statements myVar ← myVar + 1
ELSE ELSE
statements OUTPUT myVar
ENDIF ENDIF
IF bexp THEN Conditional execution (no alternative IF myVar < 15 THEN
statements branching) myVar ← myVar + 1
ENDIF ENDIF
CASE exp OF Multi-branching conditional with n num ← 3
exp1: statements choices. When exp matches expi, the CASE num OF
… statements following expi are 1: OUTPUT “One”
expn: statements computed and execution then leaves 2: OUTPUT “Two”
ELSE CASE. 3: OUTPUT “Three”
statements 4: OUTPUT “Four”
ENDCASE ELSE
OUTPUT “Out of range”
ENDCASE
WHILE bexp Conditional looping with the condition WHILE myVar ≠ 100
statements at the start of the loop. OUTPUT myVar
ENDWHILE myVar ← myVar + 1
ENDWHILE
FOR var ← iexp1 TO iexp2 Count controlled looping where var is FOR i ← 1 TO 5
statements initiated to the first integer value and OUTPUT i
ENDFOR continues to iterate incrementing by ENDFOR
one, halting iteration when the value
of var is strictly greater than the # this will output: 1, 2, 3, 4 and 5
second integer expression. var only
has scope within the FOR loop.

Copyright © 2012 AQA and its licensors. All rights reserved.


The Assessment and Qualifications Alliance (AQA) is a company limited by guarantee registered in England and Wales (company number 3644723)
and a registered charity (registered charity number 1073334). Registered address: AQA, Devas Street, Manchester M15 6EX
Syntax Meaning Example
Branching and Looping
REPEAT Conditional looping with the condition REPEAT
statements at the end of the loop. The loop must OUTPUT “Enter a number”
UNTIL bexp always execute at least once. num ← INPUT
OUTPUT num
UNTIL num = 5
Comments
# some text One line comment # this is a comment
# multiline comments will always
# start a new line with a hash
# comments may appear to the
# right of some code such as this
a ← 5 # also a comment
Functions and procedures
FUNCTION fname(param1,…,paramn) Function definition with n (possibly FUNCTION IsMember(myArr,val)
statements none) parameters. There must be at FOR i ← 1 TO LEN(myArr)
ENDFUNCTION least one RETURN statement within IF myArr[i] = val THEN
the statements. RETURN true
ENDIF
ENDFOR
RETURN false
ENDFUNCTION
RETURN exp Returning a value from within a (see above)
function: computes the value of exp,
exits the function and returns the
value of exp.
PROCEDURE pname(param1,…,paramn) Procedure definition with n (possibly PROCEDURE PoliteProc()
statements none) parameters OUTPUT “Enter your name”
ENDPROCEDURE Name ← USERINPUT
OUTPUT “Nice to meet you”
OUTPUT Name
ENDPROCEDURE

Copyright © 2012 AQA and its licensors. All rights reserved.


The Assessment and Qualifications Alliance (AQA) is a company limited by guarantee registered in England and Wales (company number 3644723)
and a registered charity (registered charity number 1073334). Registered address: AQA, Devas Street, Manchester M15 6EX
Syntax Meaning Example
Functions and procedures
name(param1,…,paramn) Invokes the procedure with identifier arr1 ← [“W”, “X”, “Y”, “Z”]
name with n parameters foundX ← isMember(arr1, “X”)
Operators
iexp1 MOD iexp2 Modulo operator a ← 5
q ← a MOD 3
# q is 2
+,-,*,/ Arithmetic operators (division can (5 * var) + 4
return real numbers, minus is unary
and binary). Precedence will always # would be written instead of:
be obvious and unambiguous by the # 5 * var + 4
use of brackets.
AND, OR, XOR Binary Boolean operators. Brackets a ← true
will be used to make precedence b ← false
obvious. c ← (a OR b) AND a
NOT Unary Boolean operators c ← NOT c

=, ≠, ≤, ≥, <, > Binary comparison operators (note # see the examples for IF, IF-ELSE # and WHILE
that = is equality, not assignment).
Length
LEN(var) Function that returns integer value myVar ← [1, 2, 3, 4]
that is length of an array or a string varLen ← LEN(myVar)
# varLen is 4

str ← “hi”
strLen ← LEN(str)
# strLen is 2

Copyright © 2012 AQA and its licensors. All rights reserved.


The Assessment and Qualifications Alliance (AQA) is a company limited by guarantee registered in England and Wales (company number 3644723)
and a registered charity (registered charity number 1073334). Registered address: AQA, Devas Street, Manchester M15 6EX
Syntax Meaning Example
Input and Output
READLINE(file, n) Returns the nth line of an external file if contents of file fruit.txt is:
(indexing starts at one) L1 apple
L2 banana
L3 clementine

line2 ← READLINE(fruit.txt, 2)
# line2 is “L2 banana”
WRITELINE(file, n, value) (Over)Writes the nth line of file with # using contents of fruit.txt from
value. If n exceeds the previous line # previous example:
numbers of file plus one then the gap
is filled with blank lines. newfruit ← “L4 dragonfruit”
WRITELINE(fruit.txt, 4, newfruit)
WRITELINE(fruit.txt, 2, “empty”)

Contents of fruit.txt is now:


L1 apple
empty
L3 clementine
L4 dragonfruit
OUTPUT message Writes the message to output. # strings will be wrapped in # speech
marks to make them # distinct from
variable names.

greeting ← ”hello”

OUTPUT “hi”
# outputs “hi”

OUTPUT greeting
# outputs “hello”
USERINPUT Waits for human input and then can answer ← USERINPUT
assign this value.
Copyright © 2012 AQA and its licensors. All rights reserved.
The Assessment and Qualifications Alliance (AQA) is a company limited by guarantee registered in England and Wales (company number 3644723)
and a registered charity (registered charity number 1073334). Registered address: AQA, Devas Street, Manchester M15 6EX
Syntax Meaning Example
Expressions and statements used in the examples
iexp An integer expression 4
6 / 4
43 MOD 2
LEN(myArr)
bexp A Boolean expression true
false
NOT a
(a OR b) AND (NOT a)
var, pname, fname Any sensible name for the variable, # see examples above
procedure or function respectively.
Assume that all names will be unique.
statements A (possibly empty) series of one line # three statements:
statements. A statement is a ← 43
terminated by a new line. b ← 16
c ← a + b

Copyright © 2012 AQA and its licensors. All rights reserved.


The Assessment and Qualifications Alliance (AQA) is a company limited by guarantee registered in England and Wales (company number 3644723)
and a registered charity (registered charity number 1073334). Registered address: AQA, Devas Street, Manchester M15 6EX

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy