Count in octal: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 14:
 
=={{header|0815}}==
<langsyntaxhighlight lang="0815">}:l:> Start loop, enqueue Z (initially 0).
}:o: Treat the queue as a stack and
<:8:= accumulate the octal digits
Line 30:
<:a:~$ Output a newline.
<:1:x{+ Dequeue the current number and increment it.
^:l:</langsyntaxhighlight>
 
=={{header|360 Assembly}}==
The program uses one ASSIST macro (XPRNT) to keep the code as short as possible.
<langsyntaxhighlight lang="360asm">* Octal 04/07/2016
OCTAL CSECT
USING OCTAL,R13 base register
Line 79:
EM12 DC X'40',9X'20',X'2120' mask CL12 11num
YREGS
END OCTAL</langsyntaxhighlight>
{{out}}
<pre style="height:20ex">
Line 108:
{{works with|https://skilldrick.github.io/easy6502/ Easy6502}}
Easy6502 can only output using a limited video memory or a hexdump. However the output is correct up to 2 octal digits.
<langsyntaxhighlight lang="6502asm">
define SRC_LO $00
define SRC_HI $01
Line 168:
ora temp ;put the bottom 3 bits of the original input back.
and #$7F ;clear bit 7.
rts</langsyntaxhighlight>
 
{{out}}
Line 180:
=={{header|8080 Assembly}}==
This assumes the CP/M operating system. The count will terminate after the largest unsigned 16-bit value is reached.
<syntaxhighlight lang="text">
;-------------------------------------------------------
; useful equates
Line 276:
;
end
</syntaxhighlight>
</lang>
{{out}}
Showing the last 10 lines of the output.
Line 294:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program countOctal64.s */
Line 395:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC PrintOctal(CARD v)
CHAR ARRAY a(6)
BYTE i=[0]
Line 424:
UNTIL i=0
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Count_in_octal.png Screenshot from Atari 8-bit computer]
Line 443:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO;
 
procedure Octal is
Line 452:
Ada.Text_IO.New_Line;
end loop;
end Octal;</langsyntaxhighlight>
First few lines of Output:
<pre> 8#0#
Line 473:
 
=={{header|Aime}}==
<langsyntaxhighlight lang="aime">integer o;
 
o = 0;
Line 480:
o_byte('\n');
o += 1;
} while (0 < o);</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
<langsyntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #
 
INT oct width = (bits width-1) OVER 3 + 1;
Line 493:
printf(($"8r"8r n(oct width)dl$, BIN i))
OD
)</langsyntaxhighlight>
Output:
<pre>
Line 517:
=={{header|ALGOL W}}==
Algol W has built-in hexadecimal and decimal output, this implements octal output.
<langsyntaxhighlight lang="algolw">begin
string(12) r;
string(8) octDigits;
Line 543:
for c := cPos - 1 step -1 until 0 do writeon( r( c // 1 ) )
end while_r_lt_MAXINTEGER
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 562:
=={{header|APL}}==
Works with [[Dyalog APL]]. 100,000 is just an arbitrarily large number I chose.
<syntaxhighlight lang APL="apl">10⊥¨8∘⊥⍣¯1¨⍳100000</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program countoctal.s */
Line 679:
bx lr @return
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">loop 1..40 'i ->
print ["number in base 10:" pad to :string i 2
"number in octal:" pad as.octal i 2]</langsyntaxhighlight>
 
{{out}}
Line 731:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AHKlang="ahk">DllCall("AllocConsole")
Octal(int){
While int
Line 741:
FileAppend, % Octal(A_Index) "`n", CONOUT$
Sleep 200
}</langsyntaxhighlight>
 
=={{header|AWK}}==
The awk extraction and reporting language uses the underlying C library to provide support for the printf command. This enables us to use that function to output the counter value as octal:
 
<langsyntaxhighlight lang="awk">BEGIN {
for (l = 0; l <= 2147483647; l++) {
printf("%o\n", l);
}
}</langsyntaxhighlight>
 
=={{header|BASIC}}==
Line 758:
{{works with|QBasic}}
 
<langsyntaxhighlight lang="qbasic">DIM n AS LONG
FOR n = 0 TO &h7FFFFFFF
PRINT OCT$(n)
NEXT</langsyntaxhighlight>
 
However, many do not. For those BASICs, we need to write our own function.
Line 767:
{{works with|Chipmunk Basic}}
 
<langsyntaxhighlight lang="qbasic">WHILE ("" = INKEY$)
PRINT Octal$(n)
n = n + 1
Line 781:
WEND
Octal$ = outp$
END FUNCTION</langsyntaxhighlight>
 
See also: [[#BBC BASIC|BBC BASIC]], [[#Liberty BASIC|Liberty BASIC]], [[#PureBasic|PureBasic]], [[#Run BASIC|Run BASIC]]
 
==={{header|Applesoft BASIC}}===
<langsyntaxhighlight ApplesoftBasiclang="applesoftbasic">10 N$ = "0"
 
100 O$ = N$
Line 798:
180 NEXT I
190 IF C THEN N$ = "1" + N$
200 GOTO 100</langsyntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">
<lang BASIC256>
valor = 0
do
Line 808:
until valor = 0
end
</syntaxhighlight>
</lang>
 
 
Line 819:
Commodore BASIC has a little quirk where numeric values converted to a string also include a leading space for the possible negative sign; this is why the <code>STR$</code> function is wrapped in a <code>RIGHT$</code> function.
 
<langsyntaxhighlight lang="gwbasic">10 n=0
20 gosub 70
30 print oc$
Line 830:
100 oc$=left$(str$(n),1)+right$(str$(r),1)+oc$
110 if q<>0 then t=q:goto 80
120 return</langsyntaxhighlight>
 
{{output}}
Line 863:
==={{header|Sinclair ZX81 BASIC}}===
The octal number is stored and manipulated as a string, meaning that even with only 1k of RAM the program shouldn't stop until the number gets to a couple of hundred digits long. I have <i>not</i> left it running long enough to find out exactly when it does run out of memory. The <code>SCROLL</code> statement is necessary: the ZX81 halts when the screen is full unless it is positively told to scroll instead.
<langsyntaxhighlight lang="basic"> 10 LET N$="0"
20 SCROLL
30 PRINT N$
Line 876:
120 GOTO 50
130 LET N$="1"+N$
140 GOTO 20</langsyntaxhighlight>
==={{header|uBasic/4tH}}===
This routine allows for any base (up to 36) and also caters for negative numbers.
<syntaxhighlight lang="text">x = 1
 
Do
Line 902:
If Pop() Then d@ = Join ("-", d@) ' apply sign if required
Return (d@)
</syntaxhighlight>
</lang>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">
@echo off
:: {CTRL + C} to exit the batch file
Line 931:
set /a todivide/=8
goto loop2
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 948:
=={{header|BBC BASIC}}==
Terminate by pressing ESCape.
<langsyntaxhighlight lang="bbcbasic"> N% = 0
REPEAT
PRINT FN_tobase(N%, 8, 0)
Line 966:
UNTIL (N%=FALSE OR N%=TRUE) AND M%<=0
=A$
</syntaxhighlight>
</lang>
 
=={{header|bc}}==
<langsyntaxhighlight lang="bc">obase = 8 /* Output base is octal. */
for (num = 0; 1; num++) num /* Loop forever, printing counter. */</langsyntaxhighlight>
 
The loop never stops at a maximum value, because bc uses [[arbitrary-precision integers (included)|arbitrary-precision integers]].
Line 976:
=={{header|BCPL}}==
This will count up from 0 until the limit of the machine word.
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let start() be
Line 984:
x := x + 1
$) repeatuntil x = 0
$)</langsyntaxhighlight>
 
=={{header|Befunge}}==
This is almost identical to the [[Binary digits#Befunge|Binary digits]] sample, except for the change of base and the source coming from a loop rather than a single input.
<langsyntaxhighlight lang="befunge">:0\55+\:8%68>*#<+#8\#68#%/#8:_$>:#,_$1+:0`!#@_</langsyntaxhighlight>
 
=={{header|BQN}}==
<code>_while_</code> and <code>Oct</code> are snippets from [https://mlochbaum.github.io/bqncrate/ BQNcrate]. A more array-oriented approach is <code>⥊↕n⥊8</code>, which produces all <code>n</code>-digit octal numbers instead of counting.
 
<langsyntaxhighlight lang="bqn">_while_←{𝔽⍟𝔾∘𝔽_𝕣_𝔾∘𝔽⍟𝔾𝕩}
Oct←8{⌽𝕗|⌊∘÷⟜𝕗⍟(↕1+·⌊𝕗⋆⁼1⌈⊢)}
{•Show Oct 𝕩, 𝕩+1} _while_ 1 0 </langsyntaxhighlight>
 
=={{header|Bracmat}}==
Stops when the user presses Ctrl-C or when the stack overflows. The solution is not elegant, and so is octal counting.
<langsyntaxhighlight lang="bracmat">
( oct
=
Line 1,008:
& -1:?n
& whl'(1+!n:?n&out$(!n oct$!n));
</syntaxhighlight>
</lang>
 
=={{header|Brainf***}}==
 
<langsyntaxhighlight lang="bf">+[ Start with n=1 to kick off the loop
[>>++++++++<< Set up {n 0 8} for divmod magic
[->+>- Then
Line 1,028:
<[[-]<] Zero the tape for the next iteration
++++++++++. Print a newline
[-]<+] Zero it then increment n and go again</langsyntaxhighlight>
 
=={{header|C}}==
<langsyntaxhighlight Clang="c">#include <stdio.h>
 
int main()
Line 1,038:
do { printf("%o\n", i++); } while(i);
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
class Program
Line 1,053:
} while (++number > 0);
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
This prevents an infinite loop by counting until the counter overflows and produces a 0 again. This could also be done with a for or while loop, but you'd have to print 0 (or the last number) outside the loop.
 
<langsyntaxhighlight lang="cpp">#include <iostream>
 
int main()
Line 1,069:
} while(i != 0);
return 0;
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">(doseq [i (range)] (println (format "%o" i)))</langsyntaxhighlight>
 
=={{header|COBOL}}==
{{trans|Delphi}}
{{works with|GNU Cobol|2.0}}
<langsyntaxhighlight lang="cobol"> >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. count-in-octal.
Line 1,120:
END-PERFORM
.
END FUNCTION dec-to-oct.</langsyntaxhighlight>
 
=={{header|CoffeeScript}}==
<langsyntaxhighlight lang="coffeescript">
n = 0
 
Line 1,129:
console.log n.toString(8)
n += 1
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(loop for i from 0 do (format t "~o~%" i))</langsyntaxhighlight>
 
=={{header|Component Pascal}}==
BlackBox Component Builder
<langsyntaxhighlight lang="oberon2">
MODULE CountOctal;
IMPORT StdLog,Strings;
Line 1,152:
END CountOctal.
 
</syntaxhighlight>
</lang>
Execute: ^Q CountOctal.Do<br/>
Output:
Line 1,178:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
typedef N is uint16;
Line 1,201:
n := n + 1;
if n == 0 then break; end if;
end loop;</langsyntaxhighlight>
 
=={{header|Crystal}}==
<langsyntaxhighlight lang="ruby"># version 0.21.1
# using unsigned 8 bit integer, range 0 to 255
(0_u8..255_u8).each { |i| puts i.to_s(8) }</langsyntaxhighlight>
 
{{out}}
Line 1,230:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">void main() {
import std.stdio;
 
Line 1,236:
do writefln("%o", i++);
while(i);
}</langsyntaxhighlight>
 
=={{header|Dc}}==
=== Named Macro ===
A simple infinite loop and octal output will do.
<syntaxhighlight lang Dc="dc">8o0[p1+lpx]dspx</langsyntaxhighlight>
 
=== Anonymous Macro ===
Needs <code>r</code> (swap TOS and NOS):
<langsyntaxhighlight Dclang="dc">8 o 0 [ r p 1 + r dx ] dx</langsyntaxhighlight>
Pushing/poping TOS to a named stack can be used instead of swaping:
<langsyntaxhighlight Dclang="dc">8 o 0 [ S@ p 1 + L@ dx ] dx</langsyntaxhighlight>
 
=={{header|DCL}}==
<langsyntaxhighlight DCLlang="dcl">$ i = 0
$ loop:
$ write sys$output f$fao( "!OL", i )
$ i = i + 1
$ goto loop</langsyntaxhighlight>
{{out}}
<pre>00000000000
Line 1,270:
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">program CountingInOctal;
 
{$APPTYPE CONSOLE}
Line 1,293:
for i := 0 to 20 do
WriteLn(DecToOct(i));
end.</langsyntaxhighlight>
 
=={{header|EDSAC order code}}==
Uses 17-bit integers, maximum 2^16 - 1 (177777 octal). It would take the original EDSAC 18 or 19 hours to exhaust these, so there is not much point in extending to 35-bit integers.
<langsyntaxhighlight lang="edsac">
[Count in octal, for Rosetta Code.
EDSAC program, Initial Orders 2.]
Line 1,359:
PF [acc = 0 on entry]
[end]
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,378:
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">Stream.iterate(0,&(&1+1)) |> Enum.each(&IO.puts Integer.to_string(&1,8))</langsyntaxhighlight>
or
<langsyntaxhighlight lang="elixir">Stream.unfold(0, fn n ->
IO.puts Integer.to_string(n,8)
{n,n+1}
end) |> Stream.run</langsyntaxhighlight>
or
<langsyntaxhighlight lang="elixir">f = fn ff,i -> :io.fwrite "~.8b~n", [i]; ff.(ff, i+1) end
f.(f, 0)</langsyntaxhighlight>
 
=={{header|Emacs Lisp}}==
Displays in the message area interactively, or to standard output under <code>-batch</code>.
 
<langsyntaxhighlight lang="lisp">(dotimes (i most-positive-fixnum) ;; starting from 0
(message "%o" i))</langsyntaxhighlight>
 
=={{header|Erlang}}==
The fun is copied from [[Integer sequence#Erlang]]. I changed the display format.
<syntaxhighlight lang="erlang">
<lang Erlang>
F = fun(FF, I) -> io:fwrite("~.8B~n", [I]), FF(FF, I + 1) end.
</syntaxhighlight>
</lang>
Use like this:
<pre>
Line 1,405:
 
=={{header|Euphoria}}==
<langsyntaxhighlight lang="euphoria">integer i
i = 0
while 1 do
printf(1,"%o\n",i)
i += 1
end while</langsyntaxhighlight>
 
Output:
Line 1,427:
 
=={{header|F Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">let rec countInOctal num : unit =
printfn "%o" num
countInOctal (num + 1)
 
countInOctal 1</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: kernel math prettyprint ;
0 [ dup .o 1 + t ] loop</langsyntaxhighlight>
 
=={{header|Forth}}==
Using INTS from [[Integer sequence#Forth]]
<langsyntaxhighlight lang="forth">: octal ( -- ) 8 base ! ; \ where unavailable
 
octal ints</langsyntaxhighlight>
 
=={{header|Fortran}}==
{{works with|Fortran|95 and later}}
<langsyntaxhighlight lang="fortran">program Octal
implicit none
Line 1,457:
n = n + 1
end do
end program</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Dim ub As UByte = 0 ' only has a range of 0 to 255
Line 1,469:
Print
Print "Press any key to quit"
Sleep</langsyntaxhighlight>
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">i = 0
while true
{
println[i -> octal]
i = i + 1
}</langsyntaxhighlight>
 
=={{header|Futhark}}==
Line 1,484:
look like octal numbers when printed in decimal.
 
<syntaxhighlight lang="futhark">
<lang Futhark>
fun octal(x: int): int =
loop ((out,mult,x) = (0,1,x)) = while x > 0 do
Line 1,494:
fun main(n: int): [n]int =
map octal (iota n)
</syntaxhighlight>
</lang>
 
=={{header|FutureBasic}}==
<langsyntaxhighlight lang="futurebasic">window 1, @"Count in Octal"
 
defstr word
Line 1,508:
next
 
HandleEvents</langsyntaxhighlight>
 
Output:
Line 1,540:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,554:
}
}
}</langsyntaxhighlight>
Output:
<pre>
Line 1,574:
</pre>
Note that to use a different integer type, code must be changed in two places. Go has no way to query a type for its maximum value. Example:
<langsyntaxhighlight lang="go">func main() {
for i := uint16(0); ; i++ { // type specified here
fmt.Printf("%o\n", i)
Line 1,581:
}
}
}</langsyntaxhighlight>
Output:
<pre>
Line 1,590:
</pre>
Note also that if floating point types are used for the counter, loss of precision will prevent the program from from ever reaching the maximum value. If you stretch interpretation of the task wording "maximum value" to mean "maximum value of contiguous integers" then the following will work:
<langsyntaxhighlight lang="go">import "fmt"
 
func main() {
Line 1,606:
i = next
}
}</langsyntaxhighlight>
Output, with skip uncommented:
<pre>
Line 1,620:
</pre>
Big integers have no maximum value, but the Go runtime will panic when memory allocation fails. The deferred recover here allows the program to terminate silently should the program run until this happens.
<langsyntaxhighlight lang="go">import (
"big"
"fmt"
Line 1,633:
fmt.Printf("%o\n", i)
}
}</langsyntaxhighlight>
Output:
<pre>
Line 1,654:
=={{header|Groovy}}==
Size-limited solution:
<langsyntaxhighlight lang="groovy">println 'decimal octal'
for (def i = 0; i <= Integer.MAX_VALUE; i++) {
printf ('%7d %#5o\n', i, i)
}</langsyntaxhighlight>
 
Unbounded solution:
<langsyntaxhighlight lang="groovy">println 'decimal octal'
for (def i = 0g; true; i += 1g) {
printf ('%7d %#5o\n', i, i)
}</langsyntaxhighlight>
 
Output:
Line 1,688:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Numeric (showOct)
 
main :: IO ()
Line 1,694:
mapM_
(putStrLn . flip showOct "")
[1 .. maxBound :: Int]</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight lang="unicon">link convert # To get exbase10 method
 
procedure main()
limit := 8r37777777777
every write(exbase10(seq(0)\limit, 8))
end</langsyntaxhighlight>
 
=={{header|J}}==
'''Solution:'''
<langsyntaxhighlight Jlang="j"> disp=.([echo) ' '(-.~":)8&#.inv
(1+disp)^:_]0x</langsyntaxhighlight>
 
The full result is not displayable, by design. This could be considered a bug, but is an essential part of this task. Here's how it starts:
 
<langsyntaxhighlight lang="j"> (1+disp)^:_]0x
0
1
Line 1,722:
10
11
...</langsyntaxhighlight>
 
The important part of this code is 8&#.inv which converts numbers from internal representation to a sequence of base 8 digits. (We then convert this sequence to characters and remove the delimiting spaces - this gives us the octal values we want to display.)
Line 1,734:
That said... note that what we are doing here is counting using an internal representation and converting that to octal for display. If we instead wanted to add 1 to a value provided to us in octal and provide the result in octal, we might instead use <code>&gt;:</code> (add 1) and wrap it in <code>&amp;.(8&amp;#.)</code> (convert argument from octal and use inverse on result) with a list of digits representing our octal number. For example:
 
<langsyntaxhighlight Jlang="j"> >:&.(8&#.)7 6
7 7
>:&.(8&#.)7 7
1 0 0
>:&.(8&#.)1 0 0
1 0 1</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">public class Count{
public static void main(String[] args){
for(int i = 0;i >= 0;i++){
Line 1,748:
}
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">for (var n = 0; n < 1e14; n++) { // arbitrary limit that's not too big
document.writeln(n.toString(8)); // not sure what's the best way to output it in JavaScript
}</langsyntaxhighlight>
 
=={{header|jq}}==
Here we use JSON strings of octal digits to represent octal numbers, and therefore there is no language-defined upper bound for the problem. We are careful therefore to select an algorithm that will continue indefinitely so long as there are sufficient physical resources. This is done by framing the problem so that we can use jq's `recurse(_)`.
<langsyntaxhighlight lang="jq"># generate octals as strings, beginning with "0"
def octals:
# input and output: array of octal digits in reverse order
Line 1,774:
[0] | recurse(octal_add1) | reverse | join("");
 
octals</langsyntaxhighlight>
To print the octal strings without quotation marks, invoke jq with the -r command-line option.
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">
<lang Julia>
for i in one(Int64):typemax(Int64)
print(oct(i), " ")
sleep(0.1)
end
</syntaxhighlight>
</lang>
I slowed the loop down with a <code>sleep</code> to make it possible to see the result without being swamped.
 
Line 1,792:
 
=={{header|Klingphix}}==
<langsyntaxhighlight Klingphixlang="klingphix">include ..\Utilitys.tlhy
 
:octal "" >ps [dup 7 band tostr ps> chain >ps 8 / int] [dup abs 0 >] while ps> tonum bor ;
Line 1,798:
( 0 10 ) sequence @octal map pstack
 
" " input</langsyntaxhighlight>
{{out}}
<pre>((0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12))</pre>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1
 
// counts up to 177 octal i.e. 127 decimal
fun main(args: Array<String>) {
(0..Byte.MAX_VALUE).forEach { println("%03o".format(it)) }
}</langsyntaxhighlight>
 
{{out}}
Line 1,830:
 
=={{header|Lang5}}==
<langsyntaxhighlight lang="lang5">'%4o '__number_format set
0 do dup 1 compress . "\n" . 1 + loop</langsyntaxhighlight>
 
=={{header|langur}}==
Line 1,838:
We use the :8x interpolation modifier to create a string in base 8 (may use base 2 to 36).
 
<langsyntaxhighlight lang="langur">val .limit = 70000
 
for .i = 0; .i <= .limit; .i += 1 {
writeln $"10x\.i; == 8x\.i:8x;"
}</langsyntaxhighlight>
 
{{out}}
Line 1,921:
 
=={{header|LFE}}==
<langsyntaxhighlight lang="lisp">(: lists foreach
(lambda (x)
(: io format '"~p~n" (list (: erlang integer_to_list x 8))))
(: lists seq 0 2000))
</syntaxhighlight>
</lang>
 
=={{header|Liberty BASIC}}==
Terminate these ( essentially, practically) infinite loops by hitting <CTRL<BRK>
<syntaxhighlight lang="lb">
<lang lb>
'the method used here uses the base-conversion from RC Non-decimal radices/Convert
'to terminate hit <CTRL<BRK>
Line 1,956:
toBase$ =right$( " " +toBase$, 10)
end function
</syntaxhighlight>
</lang>
As suggested in LOGO, it is easy to work on a string representation too.
<syntaxhighlight lang="lb">
<lang lb>
op$ = "00000000000000000000"
L =len( op$)
Line 1,989:
 
end
</syntaxhighlight>
</lang>
Or use a recursive listing of permutations with the exception that the first digit is not 0 (unless listing single-digit numbers). For each digit-place, list numbers with 0-7 in the next digit-place.
<langsyntaxhighlight lang="lb">
i = 0
while 1
Line 2,008:
next i
end sub
</syntaxhighlight>
</lang>
 
=={{header|Logo}}==
No built-in octal-formatting, so it's probably more efficient to just manually increment a string than to increment a number and then convert the whole thing to octal every time we print. This also lets us keep counting as long as we have room for the string.
 
<langsyntaxhighlight lang="logo">to increment_octal :n
ifelse [empty? :n] [
output 1
Line 2,034:
print :oct
make "oct increment_octal :oct
]</langsyntaxhighlight>
 
=={{header|LOLCODE}}==
LOLCODE has no conception of octal numbers, but we can use string concatenation (<tt>SMOOSH</tt>) and basic arithmetic to accomplish the task.
<langsyntaxhighlight LOLCODElang="lolcode">HAI 1.3
 
HOW IZ I octal YR num
Line 2,056:
IM OUTTA YR printer
 
KTHXBYE</langsyntaxhighlight>
 
=={{header|Lua}}==
 
<langsyntaxhighlight lang="lua">for l=1,2147483647 do
print(string.format("%o",l))
end</langsyntaxhighlight>
 
=={{header|M4}}==
 
<langsyntaxhighlight M4lang="m4">define(`forever',
`ifelse($#,0,``$0'',
`pushdef(`$1',$2)$4`'popdef(`$1')$0(`$1',eval($2+$3),$3,`$4')')')dnl
forever(`y',0,1, `eval(y,8)
')</langsyntaxhighlight>
 
=={{header|Maple}}==
<syntaxhighlight lang="maple">
<lang Maple>
octcount := proc (n)
seq(printf("%a \n", convert(i, octal)), i = 1 .. n);
end proc;
</syntaxhighlight>
</lang>
 
=={{header|MACRO-10}}==
<syntaxhighlight lang="macro-10">
<lang MACRO-10>
title OCTAL - Count in octal.
subttl PDP-10 assembly (MACRO-10 on TOPS-20). KJX 2022.
Line 2,116:
 
end start
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">x=0;
<lang Mathematica>x=0;
While[True,Print[BaseForm[x,8];x++]</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
<langsyntaxhighlight Matlablang="matlab"> n = 0;
while (1)
dec2base(n,8)
n = n+1;
end; </langsyntaxhighlight>
Or use printf:
<langsyntaxhighlight Matlablang="matlab"> n = 0;
while (1)
printf('%o\n',n);
n = n+1;
end; </langsyntaxhighlight>
 
If a predefined sequence should be displayed, one can use
<langsyntaxhighlight Matlablang="matlab"> seq = 1:100;
dec2base(seq,8)</langsyntaxhighlight>
or
<langsyntaxhighlight Matlablang="matlab"> printf('%o\n',seq);</langsyntaxhighlight>
 
=={{header|Mercury}}==
<syntaxhighlight lang="text">
:- module count_in_octal.
:- interface.
Line 2,160:
io.format("%o\n", [i(N)], !IO),
count_in_octal(N + 1, !IO).
</syntaxhighlight>
</lang>
 
=={{header|min}}==
{{works with|min|0.19.3}}
min has no support for octal or base conversion (it is a minimalistic language, after all) so we need to do that ourselves.
<langsyntaxhighlight lang="min">(
(dup 0 ==) (pop () 0 shorten)
(((8 mod) (8 div)) cleave) 'cons linrec
Line 2,172:
 
0 (dup octal succ)
9.223e18 int times ; close to max int value</langsyntaxhighlight>
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">ИП0 П1 1 0 / [x] П1 Вx {x} 1
0 * 7 - x=0 21 ИП1 x#0 28 БП
02 ИП0 1 + П0 С/П БП 00 ИП0 lg
[x] 1 + 10^x П0 С/П БП 00</langsyntaxhighlight>
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE octal;
 
IMPORT InOut;
Line 2,193:
INC (num)
UNTIL num = 0
END octal.</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
{{trans|C}}
Even though all integers are arbitrary precision, the maximum value that can be represented as octal using the format function is 2^64 - 1. Once this value is reached, the program terminates.
<langsyntaxhighlight lang="nanoquery">i = 0
while i < 2^64
println format("%o", i)
i += 1
end</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
 
Line 2,220:
k_ = k_.add(BigInteger.ONE)
end
</syntaxhighlight>
</lang>
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">; file: ocount.lsp
; url: http://rosettacode.org/wiki/Count_in_octal
; author: oofoe 2012-01-29
Line 2,233:
(for (i 0 (pow 2 32)) (println (format "%o" i)))
 
(exit)</langsyntaxhighlight>
 
Sample output:
Line 2,252:
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import strutils
for i in 0 ..< int.high:
echo toOct(i, 16)</langsyntaxhighlight>
 
=={{header|Oberon-2}}==
{{works with|oo2c}}
<langsyntaxhighlight lang="oberon2">
MODULE CountInOctal;
IMPORT
Line 2,271:
END
END CountInOctal.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,315:
=={{header|OCaml}}==
 
<langsyntaxhighlight lang="ocaml">let () =
for i = 0 to max_int do
Printf.printf "%o\n" i
done</langsyntaxhighlight>
 
{{out}}
Line 2,343:
 
Manual:
<langsyntaxhighlight lang="parigp">oct(n)=n=binary(n);if(#n%3,n=concat([[0,0],[0]][#n%3],n));forstep(i=1,#n,3,print1(4*n[i]+2*n[i+1]+n[i+2]));print;
n=0;while(1,oct(n);n++)</langsyntaxhighlight>
 
Automatic:
{{works with|PARI/GP|2.4.3 and above}}
<langsyntaxhighlight lang="parigp">n=0;while(1,printf("%o\n",n);n++)</langsyntaxhighlight>
 
=={{header|Pascal}}==
Line 2,354:
old string incrementer for Turbo Pascal transformed, same as in http://rosettacode.org/wiki/Count_in_octal#Logo, about 100x times faster than Dephi-Version, with the abilty to used preformated strings leading zeroes.
Added a Bit fiddling Version IntToOctString, nearly as fast.
<langsyntaxhighlight lang="pascal">program StrAdd;
{$Mode Delphi}
{$Optimization ON}
Line 2,450:
writeln('IntToOctString ',T1:8:3);
end.
</syntaxhighlight>
</lang>
{{out}}
<pre> 1 1
Line 2,495:
===A recursive approach===
For this task, recursion offers no advantage in clarity or efficiency over iteration, but it's nevertheless an instructive exercise.
<syntaxhighlight lang="pascal">
<lang Pascal>
program OctalCount;
 
Line 2,525:
readln;
end.
</syntaxhighlight>
</lang>
{{out}}
Showing last 10 lines of output
Line 2,543:
=={{header|Perl}}==
Since task says "system register", I take it to mean "no larger than machine native integer limit":
<langsyntaxhighlight lang="perl">use POSIX;
printf "%o\n", $_ for (0 .. POSIX::UINT_MAX);</langsyntaxhighlight>
Otherwise:
<langsyntaxhighlight lang="perl">use bigint;
my $i = 0;
printf "%o\n", $i++ while 1</langsyntaxhighlight>
The above count in binary or decimal and convert to octal.
This actually counts in octal.
It will run forever or until the universe ends, whichever comes first.
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
$_ = 0;
s/([^7])?(7*)$/ $1 + 1 . $2 =~ tr!7!0!r /e while print "$_\n";</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #008080;">without</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">i</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
Line 2,566:
<span style="color: #000000;">i</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</langsyntaxhighlight>-->
See [[Integer_sequence#Phix]] for something that will run in a browser, obviously use "%o" instead of "%d" to
make it display octal numbers, or more accurately in that case, mpz_get_str(i,8). <!--(phixonline)-->
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php"><?php
for ($n = 0; is_int($n); $n++) {
echo decoct($n), "\n";
}
?></langsyntaxhighlight>
 
=={{header|Picat}}==
Line 2,584:
 
 
<langsyntaxhighlight Picatlang="picat">go =>
gen(N),
println(to_oct_string(N)),
Line 2,594:
gen(I, J) :-
I2 is I + 1,
gen(I2, J).</langsyntaxhighlight>
 
{{out}}
Line 2,617:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(for (N 0 T (inc N))
(prinl (oct N)) )</langsyntaxhighlight>
 
=={{header|Pike}}==
<syntaxhighlight lang="pike">
<lang Pike>
int i=1;
while(true)
write("0%o\n", i++);
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 2,635:
=={{header|PL/I}}==
Version 1:
<langsyntaxhighlight lang="pli">/* Do the actual counting in octal. */
count: procedure options (main);
declare v(5) fixed(1) static initial ((5)0);
Line 2,658:
end inc;
 
end count;</langsyntaxhighlight>
Version 2:
<langsyntaxhighlight lang="pli">count: procedure options (main); /* 12 Jan. 2014 */
declare (i, j) fixed binary;
 
Line 2,670:
end;
 
end count;</langsyntaxhighlight>
 
{{out}}
Line 2,698:
==={{header|PL/I-80}}===
If you only need to count, and aren't bothered by leading zeroes in the output, this will do the trick simply and with a minimum of fuss.
<langsyntaxhighlight lang="pl/i">
octal_count:
procedure options (main);
Line 2,709:
 
end octal_count;
</syntaxhighlight>
</lang>
{{out}}
First and last 10 numbers of output
Line 2,735:
177777
</pre>
But a general purpose function to return the octal representation of an integer value as a string (similar to the OCT$ function in many BASICs) may prove more useful.<langsyntaxhighlight lang="pl/i">
octal_count:
procedure options (main);
Line 2,763:
 
end octal_count;
</syntaxhighlight>
</lang>
{{out}}
First and last 10 numbers of output
Line 2,791:
 
=={{header|PL/M}}==
<langsyntaxhighlight plIlang="pli">100H: /* PRINT INTEGERS IN OCTAL */
BDOS: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL */
DECLARE FN BYTE, ARG ADDRESS;
Line 2,820:
CALL PR$NL;
END;
EOF</langsyntaxhighlight>
 
=={{header|PowerShell}}==
<langsyntaxhighlight PowerShelllang="powershell">[int64]$i = 0
While ( $True )
{
[Convert]::ToString( ++$i, 8 )
}</langsyntaxhighlight>
 
=={{header|Prolog}}==
Line 2,834:
octalize will keep producing and printing octal number, there is no limit.
 
<langsyntaxhighlight Prologlang="prolog">o(O) :- member(O, [0,1,2,3,4,5,6,7]).
 
octal([O]) :- o(O).
Line 2,847:
octal(X),
(maplist(write, X), nl)
).</langsyntaxhighlight>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">Procedure.s octal(n.q)
Static Dim digits(20)
Protected i, j, result.s
Line 2,877:
CloseConsole()
EndIf
</syntaxhighlight>
</lang>
Sample output:
<pre>0
Line 2,902:
 
=={{header|Python}}==
<langsyntaxhighlight Pythonlang="python">import sys
for n in xrange(sys.maxint):
print oct(n)</langsyntaxhighlight>
 
=={{header|QB64}}==
<syntaxhighlight lang="qb64">
<lang QB64>
Dim As Integer iNum, Icount
Dim sMax As String
Line 2,922:
 
REM also QBasic example runs under QB64
</syntaxhighlight>
</lang>
 
=={{header|Quackery}}==
<langsyntaxhighlight lang="quackery">8 base put
0 [ dup echo cr 1+ again ]</langsyntaxhighlight>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket
(for ([i (in-naturals)])
(displayln (number->string i 8)))
</syntaxhighlight>
</lang>
(Racket has bignums, so this loop will never end.)
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>say .base(8) for ^Inf;</langsyntaxhighlight>
{{out}}
<pre>0</pre>
Line 2,947:
 
The technique used is to convert the decimal number to binary, and separate the binary digits in groups of three, and then convert those binary groups (numbers) to decimal.
<langsyntaxhighlight lang="rexx">/*REXX program counts in octal until the number exceeds the number of program statements*/
 
/*┌────────────────────────────────────────────────────────────────────┐
Line 2,978:
if #>sourceline() then leave /*stop if # of protons > pgm statements*/
end /*#*/
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output}}
<pre style="height:38ex">
Line 3,018:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
size = 30
for n = 1 to size
Line 3,033:
end
return output
</syntaxhighlight>
</lang>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">n = 0
loop do
puts "%o" % n
Line 3,055:
0.step do |n|
puts format("%o", n)
end</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">input "Begin number:";b
input " End number:";e
Line 3,072:
if base10 < 1 then exit for
next i
end function</langsyntaxhighlight>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">fn main() {
for i in 0..std::usize::MAX {
println!("{:o}", i);
}
}</langsyntaxhighlight>
 
=={{header|Salmon}}==
Line 3,085:
Salmon has built-in unlimited-precision integer arithmetic, so these examples will all continue printing octal values indefinitely, limited only by the amount of memory available (it requires O(log(n)) bits to store an integer n, so if your computer has 1 GB of memory, it will count to a number with on the order of <math>2^{80}</math> octal digits).
 
<langsyntaxhighlight Salmonlang="salmon">iterate (i; [0...+oo])
printf("%o%\n", i);;</langsyntaxhighlight>
 
or
 
<langsyntaxhighlight Salmonlang="salmon">for (i; 0; true)
printf("%o%\n", i);;</langsyntaxhighlight>
 
or
 
<langsyntaxhighlight Salmonlang="salmon">variable i := 0;
while (true)
{
printf("%o%\n", i);
++i;
};</langsyntaxhighlight>
 
=={{header|S-BASIC}}==
Although many BASICs have a built-in OCT$ function, S-BASIC does not, so we have to supply our own
<syntaxhighlight lang="basic">
<lang BASIC>
rem - return p mod q
function mod(p, q = integer) = integer
Line 3,130:
 
end
</syntaxhighlight>
</lang>
{{out}}
Showing first and last 10 lines of output
Line 3,158:
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">Stream from 0 foreach (i => println(i.toOctalString))</langsyntaxhighlight>
 
=={{header|Scheme}}==
<langsyntaxhighlight lang="scheme">(do ((i 0 (+ i 1))) (#f) (display (number->string i 8)) (newline))</langsyntaxhighlight>
 
=={{header|Scratch}}==
Line 3,169:
This example uses the [http://seed7.sourceforge.net/libraries/integer.htm#%28in_integer%29radix%28in_integer%29 radix] operator to write a number in octal.
 
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
const proc: main is func
Line 3,179:
incr(i);
until FALSE;
end func;</langsyntaxhighlight>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var i = 0;
loop { say i++.as_oct }</langsyntaxhighlight>
=={{header|Simula}}==
<langsyntaxhighlight lang="simula">
BEGIN
 
Line 3,211:
END;
END.
</syntaxhighlight>
</lang>
 
=={{header|Smalltalk}}==
{{works with|Smalltalk/X}}
<langsyntaxhighlight lang="smalltalk">0 to:Integer infinity do:[:n |
n printOn:Stdout radix:8.
Stdout cr.
]</langsyntaxhighlight>
{{out}}
<pre>1
Line 3,240:
 
=={{header|Sparkling}}==
<langsyntaxhighlight lang="sparkling">for (var i = 0; true; i++) {
printf("%o\n", i);
}</langsyntaxhighlight>
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">local
fun count n = (print (Int.fmt StringCvt.OCT n ^ "\n"); count (n+1))
in
val _ = count 0
end</langsyntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
func octalSuccessor(value: String) -> String {
Line 3,279:
println(n)
n = octalSuccessor(n)
}</langsyntaxhighlight>
 
{{Output}}
Line 3,305:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">package require Tcl 8.5; # arbitrary precision integers; we can count until we run out of memory!
while 1 {
puts [format "%llo" [incr counter]]
}</langsyntaxhighlight>
 
=={{header|UNIX Shell}}==
We use the bc calculator to increment our octal counter:
 
<langsyntaxhighlight lang="sh">#!/bin/sh
num=0
while true; do
echo $num
num=`echo "obase=8;ibase=8;$num+1"|bc`
done</langsyntaxhighlight>
 
===Using printf ===
Increment a decimal counter and use <code>printf(1)</code> to print it in octal. Our loop stops when the counter overflows to negative.
 
<langsyntaxhighlight lang="sh">#!/bin/sh
num=0
while test 0 -le $num; do
printf '%o\n' $num
num=`expr $num + 1`
done</langsyntaxhighlight>
 
Various recent shells have a bultin <code>$(( ... ))</code> for arithmetic rather than running <code>expr</code>, in which case
Line 3,334:
{{works with|bash}}
{{works with|pdksh|5.2.14}}
<langsyntaxhighlight lang="sh">num=0
while test 0 -le $num; do
printf '%o\n' $num
num=$((num + 1))
done</langsyntaxhighlight>
 
=={{header|VBA}}==
Line 3,344:
With i defined as an Integer, the loop will count to 77777 (32767 decimal). Error handling added to terminate nicely on integer overflow.
 
<syntaxhighlight lang="vba">
<lang VBA>
Sub CountOctal()
Dim i As Integer
Line 3,356:
Debug.Print "Integer overflow - count terminated"
End Sub
</syntaxhighlight>
</lang>
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
For i = 0 To 20
WScript.StdOut.WriteLine Oct(i)
Next
</syntaxhighlight>
</lang>
 
=={{header|Vim Script}}==
<langsyntaxhighlight lang="vim">let counter = 0
while counter >= 0
echon printf("%o\n", counter)
let counter += 1
endwhile</langsyntaxhighlight>
 
=={{header|Vlang}}==
<langsyntaxhighlight lang="vlang">import math
fn main() {
for i := i8(0); ; i++ {
Line 3,381:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,397:
=={{header|VTL-2}}==
Stops at 65535, the largest integer supported by VTL-2.
<langsyntaxhighlight VTL2lang="vtl2">1000 N=0
1010 #=2000
1020 ?=""
Line 3,414:
2090 E=E-1
2100 #=E>1*2080
2110 #=R</langsyntaxhighlight>
{{out}}
<pre>
Line 3,438:
This program prints octal numbers until the internal representation of the current integer overflows to -1; it will never do so on some interpreters.
 
<syntaxhighlight lang="whitespace">
<lang Whitespace>
 
Line 3,477:
 
 
</langsyntaxhighlight>
 
It was generated from the following pseudo-Assembly.
 
<langsyntaxhighlight lang="asm">push 0
; Increment indefinitely.
0:
Line 3,513:
3:
pop
ret</langsyntaxhighlight>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "/fmt" for Conv
 
var i = 0
Line 3,523:
System.print(Conv.oct(i))
i = i + 1
}</langsyntaxhighlight>
 
{{out}}
Line 3,553:
=={{header|XPL0}}==
XPL0 doesn't have built-in routines to handle octal; instead it uses hex.
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes; \intrinsic code declarations
 
proc OctOut(N); \Output N in octal
Line 3,569:
I:= I+1;
until KeyHit or I=0;
]</langsyntaxhighlight>
 
Example output:
Line 3,594:
 
=={{header|zig}}==
<langsyntaxhighlight lang="zig">const std = @import("std");
const fmt = std.fmt;
const warn = std.debug.warn;
Line 3,606:
warn("{}\n", buf);
}
}</langsyntaxhighlight>
 
=={{header|Z80 Assembly}}==
Line 3,613:
Outputs octal values 0 through 77 (decimal 0 to 63, or hexadecimal 0x00 to 0x3F.)
 
<langsyntaxhighlight lang="z80"> xor a ;LD A,0
ld b,&40 ;how many numbers to print.
loop_showOctal:
Line 3,671:
add a,&F0
adc a,&40 ;this sequence of instructions converts hexadecimal values to ASCII.
jp PrintChar ;hardware-specific routine, omitted. Thanks to Keith of Chibiakumas for this one!</langsyntaxhighlight>
 
{{out}}
Line 3,686:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">foreach n in ([0..]){println("%.8B".fmt(n))}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,703:
 
=={{header|ZX Spectrum Basic}}==
<langsyntaxhighlight lang="zxbasic">10 PRINT "DEC. OCT."
20 FOR i=0 TO 20
30 LET o$="": LET n=i
Line 3,712:
80 NEXT i
90 STOP
100 DEF FN m(a,b)=a-INT (a/b)*b</langsyntaxhighlight>
10,327

edits