Task

Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number.

Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached.



Related task

   Integer sequence   is a similar task without the use of octal numbers.


include "cowgol.coh";
 
typedef N is uint16; 
 
sub print_octal(n: N) is
    var buf: uint8[12];
    var p := &buf[11];
    [p] := 0;
    loop
        p := @prev p;
        [p] := '0' + (n as uint8 & 7);
        n := n >> 3;
        if n == 0 then break; end if;
    end loop;
    print(p);
end sub;
 
var n: N := 0;
loop
    print_octal(n);
    print_nl();
    n := n + 1;
    if n == 0 then break; end if; 
end loop;