There are two types of subprograms which are as follows −
1.Procedures − A procedure is defined as a subprogram that defines parameterized computations. These computations are executed by an individual call statement. Procedures represent new statements. For example, because Pascal does not have a sort statement, a user can develop a procedure to sort arrays of records and use a call to that procedure in place of the unavailable sort statement.
The general syntax of a procedure in Pascal is given as
PROCEDURE Name of Procedure (formal parameter list); {local declaration section}
BEGIN
{instruction sequence}
END;
{end of procedure}
The declaration implies that a procedure has two parts as the specification and the body. The procedure specification begins with the keyword PROCEDURE and end with the procedure name or a parameter list. Parameter declarations are optional. Procedures that take no parameters are written without parenthesis.
The procedure body begins with the keyword BEGIN and end with the keyword END followed by an optional procedure name. The procedure body has three elements such as a declarative part, an executable part, and an optional exceptional handling part.
Functions − A function is a subprogram that evaluates a value. Functions and procedures are structured identical, except that
Functions are semantically modeled on mathematical functions.
Functions have a RETURN clause.
Functions produce no side effects i.e., it changes neither its parameters nor any variables defined outside the function.