teach-ict.com logo

THE education site for computer science and ICT

2. Procedures

Procedures are a way of repeating a set of instructions without having to re-write them out every time. Take a look at the code below:

 
                 FirstName = "Joe"
                 SecondName = "Smith"
                 FullName = FirstName & SecondName
                 OUTPUT(FullName)

The first two lines declare the first and second name of a person held as variables. The third line then concatenates (i.e. joins) the names and the fourth line prints out the full name. All well and good. It is a very efficient piece of coding.

Now let's consider that three people need to have their names printed out. The pseudocode below shows how this may be written

 
                 FirstName = "Joe"
                 SecondName = "Smith"
                 FullName = FirstName & SecondName
                 OUTPUT(FullName

 
                 FirstName = "Louise"
                 SecondName = "Brown"
                 FullName = FirstName & SecondName
                 OUTPUT(FullName)                
                 
                 FirstName = "Mandy"
                 SecondName = "Jones"
                 FullName = FirstName & SecondName
                 OUTPUT(FullName)
                 

This will work, but do you notice how often the same two lines of "Fullname=" and OUTPUT code are repeated?

This is inefficient and it also makes it more likely that a programmer will introduce a mistake into the code.

You can replace these repeating lines of code with a single procedure.

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?