7.1.2
Modularity
Subroutines
Subroutines
A subroutine is a named block of code within your program.


Advantages of subroutines
Advantages of subroutines
- Easier to read:
- There are fewer long blocks of code to understand.
- More efficient:
- Blocks of code can be written once and reused many times.
- More reliable:
- Each subroutine can be individually tested to make sure it works.


Parameters and arguments
Parameters and arguments
- Parameters are special variables used to pass values into a subroutine.
- Arguments are the actual values that are passed in.


Types of subroutine
Types of subroutine
- A function is a subroutine which returns a value.
- A procedure is a subroutine which does not return a value.
Scope
Scope
The scope of a variable is the group of areas of the code from which it can be accessed.


Local scope
Local scope
- A variable defined within a subroutine will have local scope.
- This means that they can only be accessed within that subroutine.


Global scope
Global scope
- A variable can be made global by adding the 'global' keyword in front of it when it is first used.
- Global variables may be accessed by any part of the whole program.
1Components of a Computer
1.1Structure & Function of the Processor
1.2Types of Processors
2Software & Software Development
2.1Systems Software
2.2Applications Generation
2.3Software Development
3Exchanging Data
3.1Compression, Encryption & Hashing
3.3Networks
4Data Types, Data Structures & Algorithms
4.1Data Types
5Legal, Moral, Cultural & Ethical Issues
5.1Computing Related Legislation
6Elements of Computational Thinking
6.1Thinking Abstractly
6.2Thinking Procedurally
6.3Thinking Logically
7Problem Solving & Programming
7.1Programming Techniques
7.2Programming Construction
Jump to other topics
1Components of a Computer
1.1Structure & Function of the Processor
1.2Types of Processors
2Software & Software Development
2.1Systems Software
2.2Applications Generation
2.3Software Development
3Exchanging Data
3.1Compression, Encryption & Hashing
3.3Networks
4Data Types, Data Structures & Algorithms
4.1Data Types
5Legal, Moral, Cultural & Ethical Issues
5.1Computing Related Legislation
6Elements of Computational Thinking
6.1Thinking Abstractly
6.2Thinking Procedurally
6.3Thinking Logically
7Problem Solving & Programming
7.1Programming Techniques
7.2Programming Construction

Unlock your full potential with GoStudent tutoring
Affordable 1:1 tutoring from the comfort of your home
Tutors are matched to your specific learning needs
30+ school subjects covered