Procedure

From Free Pascal wiki
Revision as of 12:08, 16 January 2020 by Trev (talk | contribs) (Added see also; fixed typos)
Jump to navigationJump to search

Deutsch (de) English (en) suomi (fi) français (fr) italiano (it) русский (ru)

A procedure is a routine that does not return a value. procedure is a reserved word.

Prematurely leaving a procedure

In a procedure the routine exit can be called in order to (prematurely) leave the procedure. exit may not be supplied with any parameters, since procedures do not return any value, but functions do. Supplying a parameter to exit inside a procedure definition will yield the compile-time error “Error: Procedures cannot return a value”.

Invocation

Procedure calls are statements. They may not appear in expressions, since they do not produce a value of any kind. The following example highlights all lines with procedure calls.

 1program procedureDemo(input, output, stderr);
 2
 3var
 4	x: longint;
 5
 6procedure foo;
 7begin
 8	exit;
 9	inc(x);
10end;
11
12begin
13	x := 42;
14	foo;
15	writeLn(x);
16end.

Note, that foo contains unreachable code (inc(x) is never executed because of the [unconditional] exit).

See also