99 Bottles of Beer/Pascal: Difference between revisions

From Rosetta Code
Content added Content deleted
(moving code from main task-page to sub-page)
(→‎{{header|Pascal}}: Modified so that it's a stand-alone program, and eliminated "Format" since not all Pascals support that. Simplified code a little bit.)
Line 99: Line 99:


=={{header|Pascal}}==
=={{header|Pascal}}==
<lang pascal>procedure BottlesOfBeer;
<lang pascal>program BottlesOfBeer;
var
var
i: Integer;
i: Integer;
begin
begin
for i := 99 downto 1 do
for i := 99 downto 1 do
begin
if i = 1 then begin
writeln('One bottle of beer on the wall');
if i = 1 then
writeln('One bottle of beer');
begin
WriteLn('1 bottle of beer on the wall');
writeln('Take one down, pass it around');
WriteLn('1 bottle of beer');
writeln('No more bottles of beer on the wall');
WriteLn('Take one down, pass it around');
end else begin
WriteLn('No more bottles of beer on the wall');
writeln(i, ' bottles of beer on the wall');
writeln(i, ' bottles of beer');
Exit;
writeln('Take one down, pass it around');
end;
if i = 2 then
WriteLn(Format('%d bottles of beer on the wall', [i]));
WriteLn(Format('%d bottles of beer', [i]));
writeln('One bottle of beer on the wall')
else
WriteLn('Take one down, pass it around');
WriteLn(Format('%d bottles of beer on the wall', [Pred(i)]));
writeln(i - 1, ' bottles of beer on the wall')
WriteLn('');
end;
end. </lang>
end;
end;</lang>

Revision as of 18:01, 1 September 2015

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.


Delphi

See Pascal
Or

<lang Delphi>program Hundred_Bottles;

{$APPTYPE CONSOLE}

uses SysUtils;

const C_1_Down = 'Take one down, pass it around' ;

Var i : Integer ;

// As requested, some fun : examples of Delphi basic techniques. Just to make it a bit complex

procedure WriteABottle( BottleNr : Integer ) ; begin

 Writeln(BottleNr, ' bottles of beer on the wall' ) ; 

end ;

begin

 for i := 99 Downto 1 do begin 
 WriteABottle(i); 
 Writeln( Format('%d bottles of beer' , [i] ) ) ; 
 Writeln( C_1_Down ) ; 
 WriteABottle(i-1); 
 Writeln ; 

End ;

end.</lang>


Pascal

<lang pascal>program BottlesOfBeer; var

   i: Integer;

begin

   for i := 99 downto 1 do
       if i = 1 then begin
           writeln('One bottle of beer on the wall');
           writeln('One bottle of beer');
           writeln('Take one down, pass it around');
           writeln('No more bottles of beer on the wall');
       end else begin
           writeln(i, ' bottles of beer on the wall');
           writeln(i, ' bottles of beer');
           writeln('Take one down, pass it around');
           if i = 2 then
               writeln('One bottle of beer on the wall')
           else
               writeln(i - 1, ' bottles of beer on the wall')
       end;

end. </lang>