teach-ict.com logo

THE education site for computer science and ICT

3. Building up a procedure

The previous page has this block of code;

 
                 FirstName  "Joe"
                 SecondName  "Smith"
                 FullName  FirstName + SecondName
                 OUTPUT(FullName)

 
                 FirstName  "Lousie"
                 SecondName  "Brown"
                 FullName  FirstName + SecondName
                 OUTPUT(FullName)                
                 
                 FirstName  "Mandy"
                 SecondName  "Jones"
                 FullName  FirstName + SecondName
                 OUTPUT(FullName)
                 

The code in red is just doing the same thing, over and over. In order to create a sub-procedure, take this block of code and enclose is in a procedure statement. In pseudocode you can note that you're using a procedure with a simple keyword, like PROCEDURE or PROC:

                PROCEDURE print_name(FirstName, SecondName)
                    FullName  FirstName + SecondName
                    OUTPUT(FullName)
                ENDPROCEDURE 

Let's look at how it's put together.

First of all the beginning and end of the procedure are marked with capitalised keywords. This helps readers pick it out from the surrounding code.

The procedure is given a name. In this case, "print_name" is its name.

The procedure needs two pieces of information to work. In this case, FirstName and SecondName. We list the information given to the procedure in brackets after the name. These bits of information are called parameters. Procedures can have any number of parameters, depending on what you need them to do.

The code that the procedure will be repeating is put between the start and end of the PROCEDURE keywords. It's indented, to ensure that readers can make out the structure of the code.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: What is a procedure?