Procedure

From Higher Computing Science
Jump to: navigation, search

This article is unfinished. Please consider joining and adding to this article. Read about Page layout beforehand.

Key points

  • A procedure is a block of code that runs in sequential order.
  • Procedures allow programs to group together code, but more importantly, reuse it.
  • A procedure can be called multiple times in a program - this saves on code duplication.
  • A procedure can take parameters, which allows it to work with different items of data each time it runs.
  • The difference between a function and a procedure is that a procedure is not designed to return a value to a program. Calling a procedure is simply calling a modular block of code.

Information

Example code

In the code below, a procedure called "Draw three circles" is used three times. Each time it does the same thing (draws three circles!) but with different parameters. This means the numbers being used for length1, length2 and length3 are substituted into the code each time. The values passed to the procedure are used - reusable code that saves six lines of code, and reduces programming error because no code had to be duplicated.

Videos

Further information

Test yourself

Teaching resources