99 Bottles of Beer/Pascal: Difference between revisions

From Rosetta Code
Content added Content deleted
(99 Bottles of Beer done in Pascal-languages)
 
(moving code from main task-page to sub-page / Component Pascal)
Line 9: Line 9:
See [[99 Bottles of Beer/Pascal]]
See [[99 Bottles of Beer/Pascal]]
-->
-->

=={{header|Component Pascal}}==
BlackBox Component Builder
<lang oberon2>
MODULE BottlesOfBeer;
IMPORT StdLog;
CONST bottles = 99;

PROCEDURE Part(i: INTEGER);
BEGIN
StdLog.Int(i);StdLog.String(" bottles of beer on the wall");StdLog.Ln;
StdLog.Int(i);StdLog.String(" bottles of beer");StdLog.Ln;
StdLog.String("Take one down, pass it around");StdLog.Ln;
StdLog.Int(i - 1);StdLog.String(" bottles of beer on the wall.");StdLog.Ln;
StdLog.Ln
END Part;

PROCEDURE Sing*;
VAR
i: INTEGER;
BEGIN
FOR i := bottles TO 1 BY -1 DO
Part(i)
END
END Sing;
END BottlesOfBeer.
</lang>
Execute: ^Q BottlesOfBeer.Sing<br/>
Output:
<pre>
99 bottles of beer on the wall
99 bottles of beer
Take one down, pass it around
98 bottles of beer on the wall.

98 bottles of beer on the wall
98 bottles of beer
Take one down, pass it around
97 bottles of beer on the wall.

97 bottles of beer on the wall
97 bottles of beer
Take one down, pass it around
96 bottles of beer on the wall.

...


1 bottles of beer on the wall
1 bottles of beer
Take one down, pass it around
0 bottles of beer on the wall.
</pre>



=={{header|Pascal}}==
=={{header|Pascal}}==

Revision as of 05:20, 21 November 2014

99 Bottles of Beer/Pascal is part of 99 Bottles of Beer. You may find other members of 99 Bottles of Beer at Category:99 Bottles of Beer.

99 Bottles of Beer done in Pascal-languages


Component Pascal

BlackBox Component Builder <lang oberon2> MODULE BottlesOfBeer; IMPORT StdLog; CONST bottles = 99;

PROCEDURE Part(i: INTEGER); BEGIN StdLog.Int(i);StdLog.String(" bottles of beer on the wall");StdLog.Ln; StdLog.Int(i);StdLog.String(" bottles of beer");StdLog.Ln; StdLog.String("Take one down, pass it around");StdLog.Ln; StdLog.Int(i - 1);StdLog.String(" bottles of beer on the wall.");StdLog.Ln; StdLog.Ln END Part;

PROCEDURE Sing*; VAR i: INTEGER; BEGIN FOR i := bottles TO 1 BY -1 DO Part(i) END END Sing; END BottlesOfBeer. </lang> Execute: ^Q BottlesOfBeer.Sing
Output:

 99 bottles of beer on the wall
 99 bottles of beer
Take one down, pass it around
 98 bottles of beer on the wall.

 98 bottles of beer on the wall
 98 bottles of beer
Take one down, pass it around
 97 bottles of beer on the wall.

 97 bottles of beer on the wall
 97 bottles of beer
Take one down, pass it around
 96 bottles of beer on the wall.

...


 1 bottles of beer on the wall
 1 bottles of beer
Take one down, pass it around
 0 bottles of beer on the wall.


Pascal

<lang pascal>procedure BottlesOfBeer; var

 i: Integer;

begin

 for i := 99 downto 1 do
 begin
   if i = 1 then
   begin
     WriteLn('1 bottle of beer on the wall');
     WriteLn('1 bottle of beer');
     WriteLn('Take one down, pass it around');
     WriteLn('No more bottles of beer on the wall');
     Exit;
   end;
   WriteLn(Format('%d bottles of beer on the wall', [i]));
   WriteLn(Format('%d bottles of beer', [i]));
   WriteLn('Take one down, pass it around');
   WriteLn(Format('%d bottles of beer on the wall', [Pred(i)]));
   WriteLn();
 end;

end;</lang>