99 Bottles of Beer/Pascal: Difference between revisions

m
Fixed syntax highlighting.
(99 Bottles of Beer done in Pascal-languages)
 
m (Fixed syntax highlighting.)
 
(7 intermediate revisions by 3 users not shown)
Line 1:
<!--
===Pascal===
-->
{{collection|99 Bottles of Beer}}
Line 6:
__toc__
 
<!--
See [[99 Bottles of Beer/Pascal]]
-->
 
<span style='font-family: "Linux Libertine",Georgia,Times,serif;font-size:150%;'>[[Component Pascal]]</span><hr>
=={{header|Pascal}}==
BlackBox Component Builder
<lang pascal>procedure BottlesOfBeer;
<syntaxhighlight 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.
</syntaxhighlight>
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>
 
 
<span style='font-family: "Linux Libertine",Georgia,Times,serif;font-size:150%;'>[[Delphi]]</span><hr>
:''See [[#Pascal|Pascal]]''
 
:''Or
 
<syntaxhighlight 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.</syntaxhighlight>
 
 
<span style='font-family: "Linux Libertine",Georgia,Times,serif;font-size:150%;'>[[Pascal]]</span><hr>
<syntaxhighlight lang="pascal">program BottlesOfBeer;
 
var
i: Integerinteger;
 
begin
for i := 99 downto 1 do
if i <> 1 then
begin
if i = 1 then begin
writeln(i, ' bottles of beer on the wall');
begin
WriteLn writeln(i, '1 bottlebottles of beer on the wall');
WriteLn writeln('1Take one down, bottlepass ofit beeraround');
if i = 2 then
WriteLn('Take one down, pass it around');
WriteLn writeln('No moreOne bottlesbottle of beer on the wall');
Exit; else
writeln(i - 1, ' bottles of beer on the wall');
end;
writeln;
WriteLn(Format('%d bottles of beer on the wall', [i]));
end
WriteLn(Format('%d bottles of beer', [i]));
else
WriteLn('Take one down, pass it around');
begin
WriteLn(Format('%d bottles of beer on the wall', [Pred(i)]));
writeln('One bottle of beer on the wall');
WriteLn('');
writeln('One bottle of beer');
end;
writeln('Take one down, pass it around');
end;</lang>
writeln('No more bottles of beer on the wall');
end
end.</syntaxhighlight>
9,476

edits