7.5 Procedures and Functions Flashcards

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

Subroutines

A

Allow code that you intend to use a number of times to be grouped together under one name

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

Give some examples of built-in subroutines

A
  • print
  • input
  • int
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Procedures

A

Execute code in a subroutine but do not return anything (can have parameters)

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

Functions

A

Execute code in a subroutine but return a value

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

What are parameters?

A

Parameters are inputs to subroutines which can be used to affect the output or the process, for example, a parameter could be the age of a man or the name of a person

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

Advantages to subroutines

A
  • They are useful to break up a large program into self-contained units
  • Improves code readability
  • Improves code maintenance
  • Improves workflow (reduces development time)
  • Can be used in other programs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the scope of a variable?

A

The scope determines where the variable can be used and recognised in the program

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

Local scope

A

Variable can only be referenced and used where the instance was made (for example if it was initialised inside a function it can only be inside the function)

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

Global scope

A

A variable that can be used anywhere in the code despite it being initiated in a closed and a local area (for example a function)

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

Advantages of using local variables

A

Local variables keep a subroutine self-contained, so it can be used in any program without variable names conflicting with those used in the calling program

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