Description
A procedure
is an arrangement of coded directions that advise a PC how to run a program. A wide range of sorts of programming dialects can be utilized to manufacture a procedures. Contingent upon the programming dialect, a procedure may likewise be known as a subprogram, subroutine. In database coding procedure is nothing but a set of SQL statements that are used to execute a query. The difference between the function and procedure is that function returns a value, procedure can be defined as a set of commands that does not return value.
Description
The following is the syntax to define the procedure. The procedure
is the keyword to define.
[c]
procedure name(argument(s): type1, argument(s): type 2, ... );
< local declarations >
begin
< procedure body >
end;
[/c]
In the above syntax local declarations
will refer for functions, labels etc. The procedure body
will have set of statements to define the functionality of procedure.
Description
The procedure declaration will inform the compiler regarding name of the procedure and calling procedure, the following is the syntax to declare a procedure.
[c]procedure name(argument(s): type1, argument(s): type 2, ... );[/c]
The following is an example.
[c]procedure findMin(x, y, z: integer; var m: integer);[/c]
In the above example findMin
is the name of the procedure, xyz
are the arguments. If developer wants to use procedure then it is mandatory to call procedure to perform the task, while code calling procedure the code control will transfer to the call procedure then it will take care about defining task. The following is an example which shows how to call a procedure.
[c]var
a, b, c, min: integer;
procedure findMin(x, y, z: integer; var m: integer);
(* Finds the minimum of the 3 values *)
begin
if x < y then
m:= x
else
m:= y;
if z < m then
m:= z;
end; { end of procedure findMin }
begin
writeln(' Enter three numbers: ');
readln( a, b, c);
findMin(a, b, c, min); (* Procedure call *)
writeln(' Minimum: ', min);
end.[/c]
In the above example, the procedure call is performed at findMin(a,b,c,min)
.
Output: The result will be as follows.
[c]
Enter three numbers: 4 5 8
Minimum: 4[/c]
Functions can be defined as a partitioned blocks of code in a program, which can be called any number of times during single execution of a program.Function is ordinarily utilized for calculations where as systems are typically utilized for executing business rationale.