← IGCSE Computer Science 0478 — 8.1c Procedures and Functions

IGCSE Computer Science 0478 — 8.1c Procedures and Functions Hangman

Years 10–11 · IGCSE · 42 key terms.

Theme
Words

Every word, shuffled.

Players

Breaking a program into named, reusable blocks. See the whole journey →

Want your own words? Free Hangman Generator →

Same words, on paper

The quiet activity after the loud one. Free to print, answer keys included.

Crossword8.1c Procedures and Functions · 8.1c Procedures and Functions · 8.1c Procedures and Functions · all 6

Word search8.1c Procedures and Functions · 8.1c Procedures and Functions · 8.1b Sequence, Selection and Iteration and 8.1c Procedures and Functions · all 4

Worksheetfor any module, with answer key

When your class is on devices — Snake Break and Diamond Dash run on the same modules, with a free class.

The 42 key terms

1subroutine
A named block of code, written once, that runs whenever it is called. Procedures and functions are the two kinds, and they break a program into parts.
2PROCEDURE
A named subroutine that does a job, like outputting a line, but does not return a value. It is called as a full statement and can have parameters or none.
3FUNCTION
A named subroutine that returns a single value to the place where it is called, so the call can be used inside an expression, such as x ← Total(2, 3).
4parameter
An identifier in a subroutine definition that receives a value when the subroutine is called. It is used like a variable inside the subroutine and has a data type.
6RETURNS
Only a function has RETURNS: it gives back a value used where it is called. A procedure returns nothing and is run on its own with CALL.
7CalculateTotal
A Pascal case subroutine name: it starts with a capital letter, each word is capitalised, and it uses only letters and digits, with no spaces, no underscores and no starting digit.
8PROCEDURE ShowMenu
Starts a procedure with no parameters: the keyword PROCEDURE, then its name with no brackets. Indented statements follow, and ENDPROCEDURE closes it.
9CALL DefaultLine
CALL followed by a procedure name runs that procedure. It is a complete statement written on its own line, e.g. CALL DefaultLine. Control returns to the next line afterwards.
10CALL ShowMenu()
Control passes to the subroutine, which runs its statements in order. After its last statement, control returns to the line that follows the call.
11PROCEDURE Line(Size : INTEGER)
Defines a procedure with one parameter. In the brackets after the name, write the parameter identifier, a colon, then its data type. Size is used inside the body.
12CALL Line(60)
CALL runs the procedure Line and passes the value 60 in brackets into its parameter. A variable can be passed too, e.g. CALL Line(MySize). Different values give different results.
13PROCEDURE Show(Name : STRING, Age : INTEGER)
Several parameters are separated by commas, each with its own data type. A call gives one value for each, in the same order, such as CALL Show("Sam", 14).
14CALL Name(value1, value2)
Each value in a call must match its parameter in number, order and data type, so a STRING cannot go to an INTEGER parameter and values cannot be swapped or left out.
15Define then call
Write procedures and functions at the start of the code, before the main program. The main program comes after and holds the CALL statements and function calls that use them.
16FUNCTION GetPi RETURNS REAL
Starts a function with no parameters: the name has no brackets, RETURNS gives the data type of the value sent back, and ENDFUNCTION closes the function.
17RETURN
RETURN followed by a value or expression sends that value back to where the function was called, e.g. RETURN Number1 * Number1. It also ends the function.
18FUNCTION SumSquare(Number1:INTEGER, Number2:INTEGER) RETURNS INTEGER
A function header lists each parameter in brackets as name:TYPE, then RETURNS and the return type. The body uses the parameters in a RETURN expression and ends with ENDFUNCTION.
20SumSquare(10, 20) + 1
A function call is written inside an expression, with no CALL keyword. The returned value replaces the call, then the rest of the expression is worked out.
21OUTPUT SumSquare(10, 20)
Puts a function call inside OUTPUT. The function runs first, then the value it RETURNs is displayed. Text can be added: OUTPUT "Sum = ", SumSquare(10, 20).
22Total ← SumSquare(3, 4)
The function runs, and the value it returns is stored in the variable on the left of the arrow. You can use that variable later. Its type must match the function's return type.
23IF IsEven(Number) THEN
A function that RETURNS a BOOLEAN can be called straight in an IF or WHILE condition. The call gives TRUE or FALSE, so no comparison is needed.
24CALL SumSquare(2, 3)
A common error when SumSquare is a function. CALL is only for procedures. A function returns a value, so use it in an expression, in OUTPUT, or store it in a variable.
26DECLARE
Creates a local variable inside a procedure or function, e.g. DECLARE Length : INTEGER. It exists only while the subroutine runs and cannot be used in the main program.
27global variable
A variable declared outside every subroutine, so the main program and any procedure or function can use and change it. It exists for the whole program.
28local vs global
A local variable is declared inside a subroutine and only exists and works there while it runs. A global variable is declared outside and can be used anywhere in the program all the time.
29local variable
A variable declared inside a subroutine. It keeps the subroutine self-contained, so changing it cannot accidentally alter other parts of the program, and the subroutine is easier to test alone.
30main program
The section after all procedure and function definitions. It calls them in order, using CALL for procedures and function calls inside expressions or OUTPUT.
31trace table
A table used to trace a call: record the value given to each parameter, follow the procedure's statements, then return to the next line of the main program.
32SumSquare(10, 20)
Tracing a call: follow the function's statements to RETURN, then replace the call with the returned value (here 500) and finish evaluating the expression.
33Debugging
Finding and fixing errors by checking a subroutine's header, parameter types, RETURN, CALL, end keyword and variable scope against the syntax rules.
34library routine
A ready-made subroutine supplied with the language that you can call without writing it, such as ROUND, RANDOM or LENGTH. It saves time and avoids errors.
35DIV(a, b)
Divides a by b and returns only the whole number part, discarding any remainder. DIV(10, 3) returns 3, so it counts how many whole groups of 3 fit into 10.
36MOD(a, b)
Returns the remainder left when a is divided by b. MOD(10, 3) is 1. The result is 0 when b divides a exactly. Example: MOD(130, 60) gives the 10 leftover minutes.
37DIV(150, 60) and MOD(150, 60)
Use DIV and MOD on the same two numbers to split a value. DIV gives the whole units (2 hours) and MOD gives what is left over (30 minutes). Check: DIV * b + MOD gives a back.
38ROUND(value, places)
Library routine that returns value rounded to the given number of decimal places. ROUND(3.14159, 2) gives 3.14. If places is 0, the result is a whole number.
39RANDOM()
A library routine with empty brackets that returns a random REAL number from 0 to 1 inclusive, a different value each time it is called. Store it, e.g. Num ← RANDOM()
40ROUND(RANDOM() * 6, 0)
Gives a random whole number from 0 to 6. RANDOM() gives a decimal from 0 to 1, times 6 stretches it, and ROUND(..., 0) turns it into a whole number.
41RETURN ROUND(Price, 2)
Your own subroutine can call a library routine such as ROUND, MOD, DIV or RANDOM in its statements and use the value it gives back, for example in a RETURN.
43CALL Line(5)
Calls the Line procedure written once, so the same code is reused many times with different parameters instead of being repeated in the program.
44single point of change
Code kept in one subroutine is edited once, so every CALL gets the update. Repeated copies must each be changed, and missing one gives inconsistent results.
45modular program
A program split into small named subroutines. Each one can be tested alone and read quickly, so errors are easier to find and the whole program is easier to understand.
46benefit because reason
A full maintenance answer names a benefit of subroutines, such as one place to change, then uses because to give the reason, ideally with an example from the program, not just 'it is easier'.

Frequently Asked Questions

Do I need an account?

No. Hangman runs straight from this page — no account, no sign-up, nothing to install. If you add your class names, they are saved in your own browser and never sent to Cloodit.

How do I play it with my class?

Put the page on your whiteboard or projector and press Play. The class calls out letters and you click or type them. Six wrong letters and the word gets away. After every word its definition appears, so each round ends on the meaning, not just the spelling.

Can I use my own words?

Yes. The free Hangman generator at cloodit.com/hangman/ takes any list: one word or phrase per line, with a definition after a dash if you want it shown at the end of the round.

Can I put my students' names in?

Yes. Add your class list and a random student is called for each word. The list stays in this browser on this computer, so it is still there next lesson.

Are the worksheets free too?

Yes. Every module in this journey has a free printable worksheet with a full answer key, and there are crosswords and word searches built from the same key terms.

More IGCSE Hangman

IGCSE Computer Science 0478 — 1.1 Number Systems23 key terms IGCSE Computer Science 0478 — 1.2 Text, Sound and Images20 key terms IGCSE Computer Science 0478 — 1.3 Data Storage and Compression45 key terms IGCSE Computer Science 0478 — 2.1 Data Transmission Types and Methods36 key terms IGCSE Computer Science 0478 — 2.2 Methods of Error Detection39 key terms IGCSE Computer Science 0478 — 2.3 Encryption19 key terms Make your own hangman →Paste any word list and play