Exam Reference Language - GCSE Computers
Examination questions will be written in OCR Exam Reference Language for clarity and consistency.
Operators
The following operators will be used consistently in examination questions.
Comparison Operators
| Operator | Description | Operator | Description |
|---|---|---|---|
== | Equal to | <= | Less than or equal to |
!= | Not equal to | > | Greater than |
< | Less than | >= | Greater than or equal to |
Arithmetic Operators
| Operator | Description | Operator | Description |
|---|---|---|---|
+ | Addition | / | Division |
- | Subtraction | MOD | Modulo |
* | Multiplication | DIV | Quotient |
^ | Exponent |
Boolean Operators
| Operator | Description |
|---|---|
AND | Logical AND |
OR | Logical OR |
NOT | Logical NOT |
Core Constructs & Casting
Syntax and Examples
| Concept | Keyword(s) / Symbols | Example |
|---|---|---|
| Commenting Comment | // | |
| Variables Assignment | = | |
| Constants | const | const vat = 0.2 |
| Global Variables | global | global userID = "Cust001" |
| Input/Output Input | input(...) | myName = input("Please enter a name") |
| Output | print(...) | |
| Casting Converting to another data type | str()int()float()real()bool() | |
Control Structures Selection & Iteration
Selection
| Concept | Keyword(s) / Symbols | Example |
|---|---|---|
| Selection IF-THEN-ELSE | if ... thenelseif ... thenelseendif | |
| CASE SELECT or SWITCH | switch ... : case ... : default:endswitch | |
Iteration
| Concept | Keyword(s) / Symbols | Example |
|---|---|---|
| Iteration FOR loop (Count-controlled) | for ... to ...next ... |
This will print the word "Loop" 10 times, i.e. 0-9 inclusive. |
| FOR loop with step | for ... to ... step ...next ... |
This will print the even numbers from 2 to 10 inclusive.
This will print the numbers from 10 to 0 inclusive, i.e. 10, 9, 8,..., 2, 1, 0.
Note: the step command can be used to increment or decrement the loop by any positive or negative integer value. |
| WHILE loop (Condition-controlled) | while ...endwhile |
Will loop until the user inputs the string "Correct". Check condition is carried out before entering loop. |
| DO UNTIL loop (Condition-controlled) | dountil ... |
Will loop until the user inputs the string "Correct". Loop iterates once before a check is carried out. |
String Handling & Operations
String Operations
| Concept | Keyword(s) / Symbols | Example |
|---|---|---|
| String length | .length | |
| Substrings | .substring(x, i).left(i).right(i) |
x is starting index; i is number of characters; 0 indexed. |
| Concatenation | + | |
| Uppercase | .upper | subject.upper // gives "COMPUTERSCIENCE" |
| Lowercase | .lower | subject.lower // gives "computerscience" |
| ASCII Conversion | ASC(...)CHR(...) | ASC('A') // returns 65 (numerical)
CHR(97) // returns 'a' (char) |
File Handling & Arrays
File Handling
| Concept | Keyword(s) / Symbols | Example |
|---|---|---|
| Open | open(...) |
Note: the file needs to be stored as a variable. |
| Close | .close() | myFile.close() |
| Read line | .readLine() | myFile.readLine() // returns the next line in the file |
| Write line | .writeLine(...) |
Note: the line will be written to the END of the file. |
| End of file | .endOfFile() | |
| Create a new file | newFile() |
Creates a new text file called "myText". The file would then need to be opened using the above command for Open. |
Arrays
| Concept | Keyword(s) / Symbols | Example |
|---|---|---|
| Declaration | array colours[...] | |
| Arrays are 0 indexed Arrays only store a single data type | array gameboard[..., ...] = ... | |
| Assignment | names[...] = ...gameboard[..., ...] = ... | |
Sub programs & Random Numbers
Sub programs
| Concept | Keyword(s) / Symbols | Example |
|---|---|---|
| Procedure | procedure name(...)endprocedure | |
| Calling a procedure | procedure(parameters) | |
| Function | function name(...) ... return ...endfunction | |
| Calling a function | function(parameters) |
Note: Function returns should be stored in a variable if needed for later use in a program. |
Random Numbers
| Concept | Keyword(s) / Symbols | Example |
|---|---|---|
| Random numbers | random(..., ...) | |