Pascal. Procedure (PROCEDURE)
In Pascal routines are called procedures and functions and are described in the section with the same name.
The procedure has the same structure as the clients, but with two differences:
- Title of procedure has a different syntax and a function word procedure;
- Description of the procedure ends with a semicolon.
All names, described in the program prior to the procedure, there are in the whole program and any of its sub-program (if there are not described again.) They called global unlike localnames described in the procedure and only therein.
Production data can be transmitted through the procedure of global names or the arguments of the procedure. In the procedure, each argument has a name - the formal parameter, as described in the procedure heading under the scheme:
procedure name (list description of the formal parameters)
Description of formal parameters can be:
a list of names: the type of
var list of names: the type of
In the first case we speak about the - values (typically, they are used to input data), the second - about the - variable (used for the results of the procedure). In the simplest case, the header may comprise only the procedure procedure name.
Call operator structure is as follows:
procedure name (list of expressions);
These expressions are called actual parameters. The list must exactly match the descriptions of the list of formal parameters of the procedure. During the procedure call parameter - the value is assigned the value of the actual parameter. Actual argument here can be any expression of the appropriate type.
Actual parameter corresponding to the variable parameter, the variable must be of the same type.
Example: Create a program that is using a string of characters share the screen on the side where the prints a table of square roots for numbers 1, 2, ..., 10 and a table of natural logarithms for the numbers 1, 2, ..., 5.
Print a string of characters will issue as a procedure. Since no information transfer from the procedure in the program is not necessary, then the arguments of the procedure (type and number of characters) will be described as the - value.
program section; var x: integer: procedure line (a: integer; c: char); var j: integer; begin for j: = 1 to a do write (c); writeln end; begin line (35, '-' ) writeln ('table square roots'); line (35,' - '); for x: = 1 to 10 do writeln (x: 8, sqrt (x): 8: 4); line (35' - '); writeln (' natural logarithms table '); line (35,' - '); for x: = 1 to 5 do writeln (x: 8, ln (x): 8:4); line (35' * '); end.