3.1.1.10 Subroutines (procedures/functions) Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Define a subroutine.

A

A subroutine is a block of code which only runs when it is called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is data passed in subroutines?

A

You can pass data, known as parameters, into a method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Define a procedure.

A

A subroutine that performs a specific task. When the task is complete, the subroutine ends and the main program continues where it left off.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the two types of subroutines?

A
  • Procedures.

- Functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Outline the advantages of subroutines.

A
  • Making programs shorter, easier to read and understand through breaking down program code into smaller sections.
  • You can test procedures or functions separately rather than having to test the whole program, making programs easier to debug.
  • If something needs to be changed in a subroutine, it only needs to be changed once, within the subroutine code. This change will then take effect wherever in the program the subroutine is used.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Define a function.

A

A function works in the same way a procedure does, except it manipulates data and returns a result back from the main program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define the syntax for running a subroutine.

A

E.g. a subroutine named ‘mySubroutine’.

Syntax:

mySubroutine( );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Outline the uses of subroutines.

A

To reuse code: define the code once and use it many times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly