Year 11 Exam  >  Year 11 Notes  >  Computer for GCSE/IGCSE  >  Procedures & Functions

Procedures & Functions | Computer for GCSE/IGCSE - Year 11 PDF Download

Subroutines

Procedures and functions belong to the category of subroutines. They consist of a sequence of instructions designed to execute a particular task or series of tasks.

  • Subroutines serve to streamline programs by breaking them into smaller, more manageable segments. They offer several advantages:
    • Preventing code duplication and promoting reuse throughout the program.
    • Enhancing code readability and maintainability.
    • Facilitating various tasks such as calculations, data retrieval, and decision-making based on input.
  • Parameters, integral to subroutines, have several characteristics:
    • They enable customization of subroutine behavior.
    • They can be of diverse types.
    • Default values can be assigned, which are utilized if no value is specified.
    • Parameters can be passed either by value or by reference.
      • When passed by value, a duplicate of the parameter is created and utilized within the subroutine. In contrast, passing by reference allows the original parameter to be accessed within the subroutine, with any modifications affecting the parameter outside the subroutine.
  • Moreover, subroutines can accommodate multiple parameters.

What's the difference between a procedure and function?

Functions and procedures differ in their return behavior:

  • Functions: They return a value after performing operations or computations. This returned value can be assigned to variables or used directly in expressions.
  • Procedures: Unlike functions, procedures do not return any value. They execute a sequence of instructions or tasks without providing any result back to the caller.

In summary, functions return values, while procedures do not.

Defining and Calling a Subroutine

Once a subroutine is defined, it only needs to be set up once. Afterward, you can call it multiple times as required for usage.

Procedures

  • Procedures are established using different keywords: PROCEDURE in pseudocode, def in Python, public in Java, and Sub in Visual Basic.
  • These procedures can be invoked from different sections of the program simply by using their name.

Pseudocode example:

PROCEDURE calculate_area(length: INTEGER, width: INTEGER)
 area ← length * width
  OUTPUT "The area is " + area
END PROCEDURE
To call the procedure you would use the following pseudocode:
calculate_area(5,3)

Python example:

def calculate_area(length, width):
    area = length * width
    print("The area is ", area)
calculate_area(5,3)

Java example:

public class Main {
  static void calculateArea(int length, int width) {
    int area = length * width;
    System.out.println("The area is " + area);
  }
  public static void main(String[] args) {
    calculateArea(3,6);
  }
}

Visual Basic example:

Sub CalculateArea(length As Integer, width As Integer)
    Dim area As Integer = length * width
    Console.WriteLine("The area is " & area)
End Sub
CalculateArea(5, 3)

Question for Procedures & Functions
Try yourself:
Which of the following statements correctly describes the difference between a procedure and a function?
View Solution

Functions

  • Functions are established using distinct keywords: FUNCTION in pseudocode, def in Python, and Function in Visual Basic and Java.
  • They deliver a value by utilizing different mechanisms: RETURN in pseudocode, return statement in Python, and the function name in Visual Basic and Java.
  • Functions are callable from various program sections using their name, and the value they return can be retained in a variable.

Pseudocode example:

FUNCTION calculate_area(length: INTEGER, width: INTEGER)
  area ← length * width
  RETURN area
END PROCEDURE
To output the value returned from the function you would use the following pseudocode:
OUTPUT(calculate_area(5,3))

Python example:

def calculate_area(length, width):
    area = length * width
    return area
print(calculate_area(5,3))

Java example:

public class Main {
  static int calculateArea(int length, int width) {
   int area = length * width;
    return area;
  }
  public static void main(String[] args) {
    System.out.println(calculateArea(3,6));
  }
}

Visual Basic example:

CalculateArea(5, 3)
Sub CalculateArea(length As Integer, width As Integer)
    Dim area As Integer = length * width
    Return area
End Sub

The document Procedures & Functions | Computer for GCSE/IGCSE - Year 11 is a part of the Year 11 Course Computer for GCSE/IGCSE.
All you need of Year 11 at this link: Year 11
92 docs|30 tests

Top Courses for Year 11

FAQs on Procedures & Functions - Computer for GCSE/IGCSE - Year 11

1. What is the difference between a subroutine, a procedure, and a function?
Ans. A subroutine is a generic term for a section of code that performs a specific task. A procedure is a subroutine that does not return a value, while a function is a subroutine that does return a value.
2. How are subroutines, procedures, and functions used in programming?
Ans. Subroutines, procedures, and functions are used to break down a complex program into smaller, more manageable parts. They help improve code organization, readability, and reusability.
3. Can a function call a procedure or another function within its code?
Ans. Yes, a function can call a procedure or another function within its code. This is known as nesting functions, and it allows for more complex and flexible programming structures.
4. What are some common programming languages that support subroutines, procedures, and functions?
Ans. Some common programming languages that support subroutines, procedures, and functions include Python, Java, C++, and JavaScript.
5. How do subroutines, procedures, and functions help with debugging and troubleshooting in programming?
Ans. By breaking down a program into smaller, modular parts, subroutines, procedures, and functions make it easier to isolate and identify bugs or errors. This modular approach also makes it simpler to test and fix issues within specific sections of code.
92 docs|30 tests
Download as PDF
Explore Courses for Year 11 exam

Top Courses for Year 11

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Objective type Questions

,

Procedures & Functions | Computer for GCSE/IGCSE - Year 11

,

video lectures

,

Sample Paper

,

Procedures & Functions | Computer for GCSE/IGCSE - Year 11

,

Previous Year Questions with Solutions

,

Procedures & Functions | Computer for GCSE/IGCSE - Year 11

,

past year papers

,

Important questions

,

Viva Questions

,

Free

,

ppt

,

shortcuts and tricks

,

Summary

,

Semester Notes

,

Extra Questions

,

Exam

,

pdf

,

study material

,

mock tests for examination

,

MCQs

,

practice quizzes

;