Procedures, Parameters and Lists
Procedures
A procedure (called a function in many languages, and a My Block in Scratch) is a named group of instructions you can use again and again.
Instead of writing the square-drawing instructions every time:
define draw square
repeat 4
move 50 steps
turn 90 degrees
you just call it: draw square. Procedures make programs shorter, easier to read and easier to fix.
Parameters
A parameter is a value you give to a procedure to change how it works.
define draw square (size)
repeat 4
move (size) steps
turn 90 degrees
Now draw square (50) draws a small square and draw square (100) draws a big one.
Lists
A list stores many items in order. For example, a list called fruit might hold: apple, pear, plum.
- Each item has a position, called its index. In Scratch the first item is at position 1. In Python and many other languages the first item is at position 0.
- You can add items, delete items, replace items and ask for the length of the list. The fruit list has a length of 3.
- A loop can go through every item in a list, which is useful for a scoreboard or a quiz.
Example Uses
- A shopping list
- A list of high scores
- A list of questions for a quiz game
Decomposition
Big programs are built from small procedures, each doing one job. This makes them easier to test and fix.
Curriculum link: National Curriculum in England: Computing programmes of study (DfE) — Key Stage 2: design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts