Photo AI

Last Updated Sep 27, 2025

Functions and Procedures Simplified Revision Notes

Revision notes with simplified explanations to understand Functions and Procedures quickly and effectively.

user avatar
user avatar
user avatar
user avatar
user avatar

231+ students studying

Functions and Procedures

Overview

Functions and procedures are key components of modular programming. They allow developers to organise code into smaller, reusable blocks. Although both serve similar purposes, there are important differences in how they operate and are used.

Understanding how to define, use, and trace functions and procedures is essential for writing efficient, modular, and maintainable code.

What are Functions?

  • Definition: A function is a block of code that performs a specific task and returns a value.
  • Purpose: Used when the result of the operation needs to be used elsewhere in the program.
lightbulbExample

Example in Pseudocode:

FUNCTION calculateArea(radius)
    RETURN 3.14 * radius * radius
END FUNCTION

lightbulbExample

Example in Python:

def calculate_area(radius):
    return 3.14 * radius * radius

What are Procedures?

  • Definition: A procedure is a block of code that performs a specific task but does not return a value.
  • Purpose: Used when the task modifies data, interacts with the user or produces an output without needing to return a value.
lightbulbExample

Example in Pseudocode:

PROCEDURE displayMessage()
    PRINT "Hello, World!"
END PROCEDURE

lightbulbExample

Example in Python:

def display_message():
    print("Hello, World!")

Differences Between Functions and Procedures

AspectFunctionsProcedures
Return ValueReturns a value using RETURN.Does not return a value.
UsageUsed to perform calculations or tasks that need a result.Used to execute tasks like displaying output.
IntegrationOften used within expressions or other functions.Typically called as standalone statements.
Example Usageresult = calculateArea(5)displayMessage()

Using Functions and Procedures Together

Functions and procedures can work together to build modular, efficient programs.

infoNote

Example: Student Grade System

Function to Calculate Average:

FUNCTION calculateAverage(marks)
    total = 0
    FOR EACH mark IN marks
        total = total + mark
    ENDFOR
    RETURN total / LENGTH(marks)
END FUNCTION

Procedure to Display Result:

PROCEDURE displayResult(name, average)
    PRINT "Student:", name
    PRINT "Average Mark:", average
END PROCEDURE

Main Program:

MAIN
    marks = [85, 90, 78]
    average = calculateAverage(marks)
    displayResult("Alice", average)
END MAIN

Tracing Code with Functions and Procedures

infoNote

Example with Trace Table:

Pseudocode:

FUNCTION square(x)
    RETURN x * x
END FUNCTION

PROCEDURE printSquare(value)
    result = square(value)
    PRINT result
END PROCEDURE

MAIN
    printSquare(3)
END MAIN

Trace Table:

StepFunction/ProcedureInputOutputResult
1square(3)399
2printSquare(3)3Prints 9-

Benefits of Using Functions and Procedures

  1. Code Reusability: Functions and procedures can be called multiple times, reducing code duplication.
  2. Improved Readability: By breaking the program into smaller sections, modular code is easier to understand and maintain.
  3. Simplified Testing and Debugging: Individual functions and procedures can be tested independently.
  4. Collaborative Development: Different team members can work on different functions or procedures.

Practical Applications of Functions and Procedures

  1. Mathematical Calculations: Functions like calculateArea() or findMaximum() can handle repetitive calculations.
  2. User Interaction: Procedures like displayMenu() or printErrorMessage() manage user interactions.
  3. File Handling: Procedures can open, read, write, or close files while functions return specific data.

Note Summary

infoNote

Common Mistakes

  1. Confusing Functions and Procedures: Attempting to use a RETURN statement in a procedure or failing to return a value from a function.
  2. Incorrectly Handling Return Values: Forgetting to store or use the result of a function.
  3. Scope Errors: Misusing variables outside their intended scope.
  4. Redundant Code: Failing to use functions or procedures where appropriate, leading to repetitive code.
infoNote

Key Takeaways

  • Functions return a value and are used for tasks that produce a result.
  • Procedures do not return a value and are used for tasks that perform an action, such as printing.
  • Combining functions and procedures helps create modular code, improving readability, reusability, and maintainability.
  • Understanding and correctly using these constructs is crucial for writing efficient and organised programs.
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 Functions and Procedures

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 Functions and Procedures

Revise key concepts with interactive flashcards.

Try Computer Science Flashcards

8 quizzes

Quizzes on Functions and Procedures

Test your knowledge with fun and engaging quizzes.

Try Computer Science Quizzes

29 questions

Exam questions on Functions and Procedures

Boost your confidence with real exam questions.

Try Computer Science Questions

27 exams created

Exam Builder on Functions and Procedures

Create custom exams across topics for better practice!

Try Computer Science exam builder

12 papers

Past Papers on Functions and Procedures

Practice past papers to reinforce exam experience.

Try Computer Science Past Papers

Other Revision Notes related to Functions and Procedures you should explore

Discover More Revision Notes Related to Functions and Procedures to Deepen Your Understanding and Improve Your Mastery

96%

114 rated

Programming Techniques

Programming Constructs

user avatar
user avatar
user avatar
user avatar
user avatar

282+ studying

196KViews

96%

114 rated

Programming Techniques

Recursion and Iteration

user avatar
user avatar
user avatar
user avatar
user avatar

470+ studying

187KViews

96%

114 rated

Programming Techniques

Global and Local Variables

user avatar
user avatar
user avatar
user avatar
user avatar

384+ studying

189KViews

96%

114 rated

Programming Techniques

Modular Code

user avatar
user avatar
user avatar
user avatar
user avatar

435+ studying

198KViews
Load more notes

Join 500,000+ A-Level students using SimpleStudy...

Join Thousands of A-Level 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