View Full Screen
Line Labels:
Line labels in Pascal must be defined prior to use. There is
no such thing as a return, like in TAS. Also, Line labels
defined within a procedure are exclusive to that procedure
EXAMPLE
program labels (input,output);
label 1,2;
uses crt;
var pick:char;
procedure first;
label 1,2;
begin {begin first}
1:writeln ('This is the beginning of the subroutine');
write ('do you wish to goto the end of
the subroutine? (y/n) ');
pick := readkey;
case (pick) of
'y','Y':goto 2
else
goto 1;
end;
2:end; {end first}
begin {main program}
1: writeln ('this is beginning of the main program');
write ('Do you want to skip subroutine first (y/n): ');
pick := readkey;
case pick of
'y','Y':begin
first;
goto 1;
end
else
goto 2;
end;
2: end.
Command: (procedure)
Commands/Procedures do the same as a TAS subroutine.
values may be passed to either one, TAS or Pascal.
Procedures may only call Procedures that are coded ABOVE
the current procedure.
EXAMPLE
program commands (input,output);
var
a,b:integer;
procedure values;
var
a,b:integer;
begin
a:=15; b:=10;
writeln (a,b);
end;
begin
a:=10; b:=15;
writeln(a,b);
values;
end.
Functions:
Functions in Pascal are much the same as in TAS, but you
have to define the type of variable that is retured by the
function.
EXAMPLE
program (input,output);
var x,answer:integer
function square(x:integer):integer;
begin
square := x*x;
end;
begin
writeln ('please enter the number to be squared');
readln (x);
answer := square(x);
end.
Control Structures:
Re: CS's Pascal and TAS are similar. TAS has a database
loop which Pascal completely lacks. In Pascal CS's must
be blocked off with a begin and end, if not, it will only
execute the ONE line of code beneath it, and continue on
to the next after execution.
EXAMPLE
while (a < b) do
begin
writeln(a);
a:=a+1;
end;
for cntr:= 1 to 15 do
begin {Note that we could take out the}
{ begin and end, and this would}
writeln(cntr); { still work}
end;
{in repeat/until commands they are already blocked off}
{ a begin and end are not needed.}
cntr := 1;
repeat
writeln (cntr);
cntr := cntr + 1
until (cntr > 15)
case (cntr) of
1..3:writeln ('cntr was one, two or three.');
4:begin
writeln('cntr was 4.');
writeln('extra statement');
end;
else
writeln ('wasn''t 1, 2, 3 or 4');
end; {end of case statemen}
a:=7; b:=8;
if a > b then begin {note: where the begin is}
{placed isn't important}
writeln ('a is greater than b');
end else if b > a then begin
writeln ('b is greater than a');
end else begin
writeln ('they are equal');
end;
INPUTTING VALUES:
In Pascal you don't have the ability to control the input
as easily as TAS. You cannot default or use arrows to move
from input to input.
EXAMPLE
var x:integer;
begin
writeln ('Please enter a number');
readln (x);
end.
Outputs:
There are only two ways to output in Pascal the only difference
between the two being the carriage return.
EXAMPLE
write ('This is a test'); {This will print "this is a test"}
{leaveing te cursor at the end of}
{the output. }
writeln ('This is a test'); {This will output the same thing}
{except it will go down to the }
{next line of current window. }