Jump to content

[PASCAL] Procedures ( Structured programming )


CouldnoT
 Share

Recommended Posts

Procedures

 

This time we need to write our own procedures that can be used by our applications.

 

In the next example we have written two procedures: SayHello and SayGoodbye:

 

program Structured;
uses cthreads, Classes;

procedure SayHello;
begin
 Writeln('Hello there');
end;

procedure SayGoodbye;
begin
 Writeln('Good bye');
end;

begin // Here main application starts
 Writeln('This is the main application started');
 SayHello;
 Writeln('This is structured application');
 SayGoodbye;

 Readln;
end.

 

We see that the procedure looks like a small program, with its own begin..end, and it can be called from the main application's code.

 

Parameters

 

In the next example, we introduce parameters, which are variables passed to a procedure when calling it:

 

procedure WriteSumm(x, y: Integer);
begin
 Writeln('The summation of ', x, ' + ', y, ' = ', x + y)
end;
begin
 WriteSumm(2, 7);
 Write('Press enter key to close');
 Readln;
end. 

 

In the main application, we have called the WriteSumm procedure and passed the values 2, 7 to it, and the procedure will receive them in x, y integer variables to write the summation result of them.

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.