Photo AI

Last Updated Sep 26, 2025

Sub Programs Simplified Revision Notes

Revision notes with simplified explanations to understand Sub Programs quickly and effectively.

user avatar
user avatar
user avatar
user avatar
user avatar

358+ students studying

Sub Programs

Sub programs are smaller, reusable blocks of code that are used to structure larger programs. They allow you to break down complex problems into smaller, manageable tasks. The two main types of sub programs are functions and procedures.

Functions and Procedures

  • Functions and procedures both help to create structured code by organizing logic into independent blocks.
  • Functions return a value after performing a task, whereas procedures do not return a value. | Type | Definition | Example | |---|---|---| | Function | A sub program that returns a value. | function triple(number)
    return number * 3
    endfunction
    Calling: y = triple(7) | | Procedure | A sub program that performs a task but does not return a value. | procedure greeting(name)
    print("Hello " + name)
    endprocedure
    Calling: greeting("Hamish") |

Using Sub Programs Effectively

  • Functions and procedures can be used to improve code structure by avoiding repetition, making the program easier to read and maintain.
  • They allow modular programming, where each part of the program does one thing and can be reused in different contexts.

Where to Use Sub Programs

  • When performing repetitive tasks to avoid code duplication.
  • To break down a complex problem into simpler, smaller tasks.
  • When returning a specific result (use a function) or just executing a task without needing a return value (use a procedure).

Local and Global Variables

Sub programs can use two types of variables:

  • Local variables/constants: Declared inside a sub program and only accessible within it. These are useful for keeping data isolated to avoid conflicts with other parts of the program.
  • Global variables/constants: Declared outside any sub program and accessible throughout the entire program. Be cautious when using global variables as they can cause unintended side effects if modified unexpectedly.

Arrays in Sub Programs

Arrays can be passed to and returned from sub programs, allowing the manipulation of multiple values at once:

Passing an Array

Arrays can be passed into sub programs as arguments, allowing you to perform operations on large sets of data.

Example:

procedure printNames(names)
    for name in names:
        print(name)
endprocedure

Calling: printNames(["Bob", "Alice", "Eve"])

Returning an Array

Functions can also return arrays, which allows them to process and return multiple values at once.

Example:

function getMultiples(numbers)
    for i in range(0, len(numbers)):
        numbers[i] = numbers[i] * 2
    return numbers
endfunction
infoNote

Key Points to Remember

  • Functions return a value, while procedures do not.
  • Sub programs use local and global variables, but local variables help avoid conflicts within the program.
  • Arrays can be passed to and returned from sub programs, making them useful for processing lists of data efficiently.
Books

Only available for registered users.

Sign up now to view the full note, or log in if you already have an account!

500K+ Students Use These Powerful Tools to Master Sub Programs

Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!

80 flashcards

Flashcards on Sub Programs

Revise key concepts with interactive flashcards.

Try Computer Science Flashcards

8 quizzes

Quizzes on Sub Programs

Test your knowledge with fun and engaging quizzes.

Try Computer Science Quizzes

8 questions

Exam questions on Sub Programs

Boost your confidence with real exam questions.

Try Computer Science Questions

1 exams created

Exam Builder on Sub Programs

Create custom exams across topics for better practice!

Try Computer Science exam builder

13 papers

Past Papers on Sub Programs

Practice past papers to reinforce exam experience.

Try Computer Science Past Papers

Other Revision Notes related to Sub Programs you should explore

Discover More Revision Notes Related to Sub Programs to Deepen Your Understanding and Improve Your Mastery

96%

114 rated

Additional Programming Techniques

String Manipulation

user avatar
user avatar
user avatar
user avatar
user avatar

296+ studying

187KViews

96%

114 rated

Additional Programming Techniques

File Handling

user avatar
user avatar
user avatar
user avatar
user avatar

373+ studying

193KViews

96%

114 rated

Additional Programming Techniques

Records to Store Data

user avatar
user avatar
user avatar
user avatar
user avatar

312+ studying

185KViews

96%

114 rated

Additional Programming Techniques

SQL

user avatar
user avatar
user avatar
user avatar
user avatar

365+ studying

190KViews
Load more notes

Join 500,000+ GCSE students using SimpleStudy...

Join Thousands of GCSE Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!

97% of Students

Report Improved Results

98% of Students

Recommend to friends

500,000+

Students Supported

50 Million+

Questions answered