Procedures

As you move through your lessons on programming you will find that you use more subroutines to save yourself time. As programmers it means we write fewer lines of code, which is brilliant but it also saves the computer time and effort too.

Programming Procedures - computer science tutor

The great thing about a subroutine is that the computer doesn’t have to assign any memory to it until the program uses the code, and when the subroutine is over any memory that was used is recycled freeing up the space for something else.

At GCSE we study procedural programming and so the only two subroutine types that we need to be concerned about are procedures and functions. All subroutines are a block of code that has a name and sits outside of the main program – procedures use this technique to perform a task that doesn’t need to send any data back.

Imagine that you have been asked to tidy your room – you don’t need to report back on the success of the task, or send back the percentage of the room that is now tidy, it just needs to get done. In the same way, a procedure completes a task and then the program carries on. In pseudocode, this might look like:

PROCEDURE seeMenu()

    OUTPUT “Please choose an option:”

    OUTPUT “A: Deutsch”

    OUTPUT “B: English”

    OUTPUT “C: Espanol”

END PROCEDURE

Note that here, there is no place to input or any validation. But this procedure will also never run until we add the line seeMenu() to the main code, and that’s because subroutines are like dogs and don’t run until they are ‘called’.

The Python program below has implemented this algorithm, but there are some things missing… Calling the procedure! We do this by adding the name of the subroutine followed by brackets. Try expanding the program so that the menu appears when the program is run. To run the program in the browser, press Ctrl + Enter.

 

Where next? Try reading about Functions, or make your Subroutines even better with Parameters.

Find this page helpful? Share the love on your social media mentioning @TeachAllAboutIT and we’ll enter you in our monthly draw to win a gift voucher for any product on the site!

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on reddit

More For Members

Lesson Plan

Coming Soon!

Presentation

Coming Soon!

Homework

Coming Soon!

Students

Coming Soon!

Not a member yet? Sign Up Here

Sign Up For Membership Today

Level Price  
Individual Student £2.50 per Month. After your initial payment, your first payment is Free. Select
Whole School £12.50 per Month. Select