3. Building procedures
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 procedure, take this block of code and enclose is in a procedure statement. In pseudocode you can note that you are using a procedure with a simple keyword, such as PROCEDURE or PROC:
PROCEDURE print_name(FirstName, SecondName)
FullName = FirstName & SecondName
OUTPUT(FullName)
ENDPROCEDURE
Let's look at how it is 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 - or none at all, 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 is 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?