Procedures in Pascal are sub-programs that return a group of results. They are defined using the procedure
keyword.
The following snippet shows how procedures are generally defined:
procedure name(argument(s): type1, argument(s): type2, ... );
{local declarations}
begin
{procedure body}
end;
Arguments create a link between the calling program and the procedure. They are also called formal parameters.
These refer to the declarations for variables, constants, functions, procedures, and labels whose scope is limited to the procedure itself.
This is where the procedure defines its implementations and calculations. The procedure body is enclosed between the keywords begin
and end
.
The following code shows the implementation of a procedure in Pascal:
program Example;
var
a, b, max: integer;
procedure findBigger(x, y: integer; var m: integer);
{ Finds the maximum of the 2 values }
begin
if x > y then
m := x
else
m := y;
end; { end of procedure findBigger }
begin
a = 2
b = 3
findBigger(a, b, max); {procedure call}
writeln(' The larger number is: ', min); {prints 3}
RELATED TAGS
CONTRIBUTOR
View all Courses