AeroLab Reading room

CS / AS level

Programming and software development

Procedures, functions, parameters and structured control flow allow programs to be decomposed. Scope defines where names are visible; pass-by-value and reference-like behaviour affect which changes reach the caller.

Learning objectives

The big idea

Procedures, functions, parameters and structured control flow allow programs to be decomposed. Scope defines where names are visible; pass-by-value and reference-like behaviour affect which changes reach the caller.

Requirements, design, implementation, testing and maintenance form a development process. Choose tests from specifications and risks, not only examples that the implementation already handles.

Worked example

A function returns n×n. What is returned for n=5?

Follow the solution

Substitute 5 into the defined expression: 5×5=25.

Investigate and explain

Predict the worked result before calculating. Change one input, record the new result, and explain which assumptions still hold.

Use the prediction activity below; a local model appears only where it supports this topic.

Open the interactive investigation

Check your understanding

1. What is a local variable?

  1. A variable stored only on a local network
  2. A variable whose scope is limited to its block or subprogram
  3. A global constant
Check the answer and reasoning

A variable whose scope is limited to its block or subprogram

Local scope limits where the name can be used.

2. A function returns n×n. What is returned for n=5?

  1. 10
  2. 125
  3. 25
Check the answer and reasoning

25

Substitute 5 into the defined expression: 5×5=25.

3. Should invalid inputs be included in testing?

  1. Yes
  2. No
  3. Only after release
Check the answer and reasoning

Yes

A robust specification includes rejection or handling of invalid data, which must be tested.