English National Curriculum:
Key Stage 2
Tooltip content
To use selection, repetition, and sequences in programs and to work with variables and various forms of input and output.
learning objectives
Tooltip content
To understand that functions are like workers in computer programming. To understand the inputs and outputs of functions.
success criteria
- I can explain the importance of workers (functions) in computer programming.
- I can explain how the workers (functions) operate in computer programming.
- I understand the input and output of a function.
top tips
- Each worker in computer programming has its own name and purpose.
- Most workers in computer programming have inputs and outputs.
Common misconceptions
- All workers in computer programming have an input or output.
- Some workers in programming do not have an input or output. For example, a clock is a worker that has an output, but not an input.
- A name and an input for a worker is not enough for us.
- Using the input and worker, we can work out the output.
Functions
Inputs
Outputs
A function is a set of programming instructions. It changes an input to a desired output result. When the input or the function changes, the output changes as a result. We can think of functions as little robots, each designed to do a specific task.
A value that goes into a function.
A value that comes out of a function.
TOPIC BACKGROUND READING
Functions are a way of grouping a sequence of commands / set of code under one name. Functions allow for separation of code, so we can easily use the function code again and again throughout our program.
Functions ‘Encapsulate’ a task (they combine many instructions into a single segment of code). Most programming languages provide many built in functions that would otherwise require many steps to accomplish, for example computing the square root of a number. In general, we don’t need to know how a function does what it does, only that it ‘does it’.
When a function is ‘called’ the program ‘leaves’ the current section of code and begins to execute the first line inside the function. It continues on this path until the function is complete, at which point it returns to its original position.
We can relate this to Robians that have functions they enact. We can call them to do their jobs with their name and trust them to complete their job without having to know the details.