tutorials/pascal/Pow2.pas

29 lines
401 B
ObjectPascal

{ Prints powers of 2 less than 20,000 }
program Pow2;
const
ZERO = 1;
var
prev, this, i: integer;
begin
prev := ZERO;
for i := 1 to 15 do
begin
// Each loop is 2^i-1
if i = 1 then
this := prev
else
this := prev * 2;
prev := this;
case i of
15: writeln(this:6);
5, 10: writeln(this:6, ',');
else write(this:6, ', ')
end;
end;
end.