Procedures are used to perform tasks such as displaying menu choices to a user. The procedure (module) consists of a set of program statements, grouped by the begin and end keywords. Each procedure is given a name, similar to the title that is given to the main module.
Any variables used by the procedure are declared before the keyword begin.
The above procedure called DISPLAY_MENU, simply executes each of the statements in turn. To use this in a program, we write the name of the procedure, eg,
PROCEDURE DISPLAY_MENU;
begin
writeln('<14>Menu choices are');
writeln(' 1: Edit text file');
writeln(' 2: Load text file');
writeln(' 3: Save text file');
writeln(' 4: Copy text file');
writeln(' 5: Print text file')
end;
In the main portion of the program, it executes the statement
program PROC1 (output);
PROCEDURE DISPLAY_MENU;
begin
writeln('<14>Menu choices are');
writeln(' 1: Edit text file');
writeln(' 2: Load text file');
writeln(' 3: Save text file');
writeln(' 4: Copy text file');
writeln(' 5: Print text file')
end;begin
writeln('About to call the procedure');
DISPLAY_MENU;
writeln('Now back from the procedure')
end.
then calls the procedure DISPLAY_MENU. All the statements in this procedure are executed, at which point we go back to the statement which follows the call to the procedure in the main section, which is,
writeln('About to call the procedure');
The sample output of the program is
writeln('Now back from the procedure')
About to call the procedure
Menu choices are
1: Edit text file
2: Load text file
3: Save text file
4: Copy text file
5: Print text file
Now back from the procedure