Count in octal: Difference between revisions

no edit summary
No edit summary
Line 2,492:
IncStr 0.944 secs
IntToOctString 2.218 secs</pre>
 
==={{A recursive approach}}===
For this task, recursion offers no advantage in clarity or efficiency over iteration, but it's nevertheless an instructive exercise.
<lang Pascal>
program OctalCount;
 
{$mode objfpc}{$H+}
 
var
i : integer;
 
// display n in octal on console
procedure PutOctal(n : integer);
var
digit, n3 : integer;
begin
n3 := n shr 3;
if n3 <> 0 then PutOctal(n3);
digit := n and 7;
write(digit);
end;
 
// count in octal until integer overflow
begin
i := 1;
while i > 0 do
begin
PutOctal(i);
writeln;
i := i + 1;
end;
readln;
end.
</lang>
{{out}}
Showing last 10 lines of output
<pre>
17777777766
17777777767
17777777770
17777777771
17777777772
17777777773
17777777774
17777777775
17777777776
17777777777
</pre>
 
=={{header|Perl}}==
211

edits