All Subjects



AP Comp Sci P



Big Idea 3: Algorithms and Programming

Calling Procedures

2 min read•november 16, 2020


Minna Chow

AP Computer Science Principles ⌨️

Bookmarked 2.3k • 69 resources
See Units

A procedure is a group of programming instructions. They're also known as methods or functions, depending on the programming language. You can use a procedure to use the same set of instructions, again and again, without having to rewrite it into your code.
In AP Pseudocode, here's how they'll represent procedures:
Let's go a little into what this means.

Parts of a Procedure:

Let's go back to this example we used earlier for a program that sums two numbers.
first_number = 5 second_number = 7 sum_value = first_number + second_number print (sum_value)
It goes without saying that, if you wanted to sum more than one set of numbers at a time, you'd have to rewrite these lines over and over again...
Let's see how we'd go about writing this as a function, or a procedure in Python.
A function in Python looks like this:
def name_of_function (parameter1, parameter2): #code statements here
So our summing machine would look like this!
def summing_machine(first_number, second_number): print (first_number + second_number)
What are those parentheses for? Procedures often require some sort of parameter in order to work. Parameters are the input variables of a procedure. In this case, the parameters are the two numbers you want to add together: first_number and second_number.
❗ You don't always need to use parameters in a procedure.
When you call a procedure, your program acts like those lines of code are written out. Once it's done executing those code lines, your program goes back to reading code sequentially.
When you call that procedure with defined values or variables, those values are known as arguments.
def summing_machine(first_number, second_number): print (first_number + second_number) summing_machine(5, 7) #In this example, 5 and 7 are examples of arguments.
If you have a procedure in a longer chunk of code and you want to exit the function, you can use the return statement, in both Python and Pseudocode. This will return the value of an expression that you can then use, without needing to print it.
For example:
def summing_machine(first_number, second_number): value = first_number + second_number return (value) answer = summing_machine(5, 7) print (answer) #you can use this to manipulate the value the function returns as well. print (answer + 1)
Note that the Pseudocode allows you to assign this returned value to a variable using an arrow.

Was this guide helpful?

Join us on Discord
Thousands of students are studying with us for the AP Computer Science Principles exam.
join now
Hours Logo
Studying with Hours = the ultimate focus mode
Start a free study session
🔍 Are you ready for college apps?
Take this quiz and find out!
Start Quiz
Browse Study Guides By Unit
🕹Big Idea 1: Creative Development
⚙️Big Idea 2: Data
📱Big Idea 3: Algorithms and Programming
🖥Big Idea 4: Computer Systems and Networks
⌨️Big Idea 5: Impact of Computing
📝Exam Prep
Join us on Discord
Thousands of students are studying with us for the AP Computer Science Principles exam.
join now
💪🏽 Are you ready for the AP CSP exam?
Take this quiz for a progress check on what you’ve learned this year and get a personalized study plan to grab that 5!