Begin Programming Logo
Home | KPL | Object Pascal | General Programming | Code Database | About Us
   
Procedure/Methods
   
   

Methods and procedures are basically the same things. However some languages call
them methods, others call them procedures. For the purpose of this article I will
refer to them as procedures.

When writing a program bits of code are often reused. In order to do this efficiently a
procedure is used. This procedure encloses the block of code. Every time you
want to access the code all you have to do is to "call" the procedure. You do this
by writing the name of the procedure.

Example

Procedure HelloWorld
  Begin
    Write('Hello World')
  End

Begin
  Write('My hello world program')
  HelloWorld
End

In order to make procedures even more useful programmers created an interface for
the procedure. This interface is used to pass information into the procedure.

Example

Procedure Add(Number1, Number2)
  Begin
    Write(Number1 + Number2)
  End

This procedure lets you add any two numbers together. All you have to do is call the
procedure and write the numbers in the brackets.

Example

Add(5, 10)

Obviously the exact code for creating and calling procedures varies between
programming languages however most tend to follow this general structure.
   

Valid XHTML 1.0 Transitional Valid CSS!