Integer sequence: Difference between revisions

 
(43 intermediate revisions by 23 users not shown)
Line 11:
 
=={{header|0815}}==
<langsyntaxhighlight lang="0815">}:_:<:1:+%<:a:~$^:_:</langsyntaxhighlight>
 
=={{header|11l}}==
<langsyntaxhighlight lang="11l">L(i) 1..
print(i)</langsyntaxhighlight>
 
=={{header|360 Assembly}}==
For maximum compatibility, this program uses only the basic instruction set (S/360).
<langsyntaxhighlight lang="360asm">* Integer sequence 06/05/2016
INTSEQED CSECT
USING INTSEQED,12
Line 33:
DW DS 0D,PL8 pack dec 15num
EM12 DC X'402020202020202020202120' mask CL12 11num
END INTSEQED</langsyntaxhighlight>
{{out}}
<pre>
Line 49:
...
</pre>
 
=={{header|6502 Asembler}}==
 
I no longer have my personal copy of:
6502 assembly language subroutines
by Lance A. Leventhal, Winthrop Saville
pub Osborne/McGraw-Hill
(destroyed in bushfire)
It is available on the Wayback Machine (archive.org)
Pages 253ff contains a general purpose Multiple-Precision Binary Addition subroutine
Not needing to re-invent the wheel, I used this as the basis for my solution.
 
.multiple_precision_add
 
=={{header|8080 Assembly}}==
Actually printing the numbers out would depend on the hardware and operating system.
<langsyntaxhighlight lang="8080asm"> ORG 0100H
MVI A, 0 ; move immediate
LOOP: INR A ; increment
Line 58 ⟶ 72:
JMP LOOP ; jump unconditionally
 
END</langsyntaxhighlight>
 
A more complex, arbitrary precision version that can count as high as you have free bytes of memory to use. (This does assemble with CP/M's MAC assembler, but since it doesn't implement PRBUFR, it's only useful for exposition purposes, or for loading into DDT.)
 
<langsyntaxhighlight lang="8080asm">
ORG 0100H
BITS EQU 128 ; 128 bits of precision
Line 96 ⟶ 110:
BUFR: ; This space will hold our number
; We zero this memory before the loop
END</langsyntaxhighlight>
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC Main()
CARD i
 
Line 108 ⟶ 122:
UNTIL i=0
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Integer_sequence.png Screenshot from Atari 8-bit computer]
Line 116 ⟶ 130:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO;
procedure Integers is
Value : Integer := 1;
Line 124 ⟶ 138:
Value := Value + 1; -- raises exception Constraint_Error on overflow
end loop;
end Integers;</langsyntaxhighlight>
Alternative (iterating through all values of Positive (positive part of Integer) without endless loop):
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO;
procedure Positives is
begin
Line 132 ⟶ 146:
Ada.Text_IO.Put_Line (Positive'Image (Value));
end loop;
end Positives;</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
Line 139 ⟶ 153:
{{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''.}}
The upper limit of the loop variable ''i'' is ''max int'' currently ''+2147483647'' for [[ALGOL 68G]].
<langsyntaxhighlight lang="algol68">main:
(
FOR i DO
printf(($g(0)","$,i))
OD
)</langsyntaxhighlight>
Partial output:
<pre>
Line 151 ⟶ 165:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
% print the integers from 1 onwards %
% Algol W only has 32-bit integers. When i reaches 2^32, %
Line 162 ⟶ 176:
i := i + 1
end loop_forever ;
end.</langsyntaxhighlight>
 
=={{header|Applesoft BASIC}}==
Integer variables can be within the range of -32767 to 32767.
<langsyntaxhighlight Applesoftlang="applesoft BASICbasic"> 10 I% = 1
20 PRINT I%;
30 I% = I% + 1
40 PRINT ", ";
50 GOTO 20</langsyntaxhighlight>
Last screen of scrolled output:
<langsyntaxhighlight Applesoftlang="applesoft BASICbasic">, 32646, 32647, 32648, 32649, 32650, 326
51, 32652, 32653, 32654, 32655, 32656, 3
2657, 32658, 32659, 32660, 32661, 32662,
Line 195 ⟶ 209:
, 32766, 32767
?ILLEGAL QUANTITY ERROR IN 30
]</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
<langsyntaxhighlight lang="armasm">.text
.global main
 
Line 212 ⟶ 226:
@ call to 'PRINT' routine
add r0, r0, #1 @ increment R0
b repeat @ unconditional branch</langsyntaxhighlight>
 
Alternative version
 
<pre>
Developed on an Acorn A5000 with RISC OS 3.10 (30 Apr 1992)
Using the assembler contained in ARM BBC BASIC V version 1.05 (c) Acorn 1989
 
The Acorn A5000 is the individual computer used to develop the code,
the code is applicable to all the Acorn Risc Machines (ARM)
produced by Acorn and the StrongARM produced by digital.
 
Investigation (a)
If all that was needed was to increment without doing the required display part of the task
then:
.a_loop
ADDS R0 , R0, #1
ADCS R1 , R1, #0
ADCS R2 , R2, #0
ADCS R3 , R3, #0
B a_loop
will count a 128 bit number
Investigation (b)
How long does it take?
.b_loop_01 \ took 71075 cs = 11.85 mins
ADDS R0, R0, #1 \ only a single ADD in the loop - unable to get the pipeline going
B B_loop_01
.b_loop_04 \ took 31100 cs = 5.18 mins
ADDS R0, R0, #1 \ with four instructions within the loop
ADDS R0, R0, #1
ADDS R0, R0, #1
ADDS R0, R0, #1
B B_loop_04
.b_loop_16 \ took 21112 cs = 3.52 mins
ADDS R0, R0, #1 \ with sixteen instructions within the loop
followed by a further 15 ADDS instructions
B B_loop_16
so there clearly is a time advantage to putting enough inline instructions to make the pipeline effective
But beware - for a 64 bit number (paired ADDS and ADCS) it took 38903 cs = 6.48 mins to count to only 32 bits,
a 128 bit number will take 4,294,967,296 * 4,294,967,296 * 4,294,967,296 times 6.48 mins.
My pet rock will tell you how long that took as it will have evolved into a sentient being by then.
The task
Producing a solution in say 64 bits or 128 bits is trivial when only looking at the increment.
Hovever the display part of the task is very difficult.
So instead go for BCD in as many bits as required. This makes the increment more involved, but
the display part of the task becomes manageable.
So a solution is:
.bcd_32bits_vn02
MOV R4 , #0 \ if eventually 4 registers each with 8 BCD
MOV R5 , #0 \ then 32 digits total
MOV R6 , #0
MOV R7 , #0
MOV R8 , #0 \ general workspace
MOV R9 , #0 \ a flag in the display - either doing leading space or digits
MVN R10 #&0000000F \ preset a mask of &FFFFFFF0
\ preset in R10 as the ARM has a very limited
\ range of immediate literals
MOV R11 , #&F \ preset so can be used in AND etc together with shifts
B bcd_32bits_loop_vn02 \ intentionally jump to inside the loop as this
\ single branch saves the need for multiple branches
\ later on (every branch resets the instruction pipeline)
\ the repeated blocks of code could be extracted into routines, however as they are small
\ I have decided to keep them as inline code as I have decided that the improved execution
\ from better use of the pipeline is greater than the small overall code size
.bcd_32bits_display_previous_number_vn02
MOV R9 , #0 \ start off with leading spaces (when R9<>0 output "0" instead)
ANDS R8 , R11 , R4, LSR#28 \ extract just the BCD in bits 28 to 31 of R4
MOVNE R9 , #1 \ if the BCD is non-zero then stop doing leading spaces
CMP R9 , #0 \ I could not find a way to eliminate this CMP
MOVEQ R0 , #&20 \ leading space
ORRNE R0 , R8 , #&30 \ digit 0 to 9 all ready for output
SWI OS_WriteC \ output the byte in R0
ANDS R8 , R11 , R4, LSR#24 \ extract just the BCD in bits 24 to 27 of R4
MOVNE R9 , #1
CMP R9 , #0
MOVEQ R0 , #&20
ORRNE R0 , R8 , #&30
SWI OS_WriteC
ANDS R8 , R11 , R4, LSR#20 \ extract just the BCD in bits 20 to 23 of R4
MOVNE R9 , #1
CMP R9 , #0
MOVEQ R0 , #&20
ORRNE R0 , R8 , #&30
SWI OS_WriteC
ANDS R8 , R11 , R4, LSR#16 \ extract just the BCD in bits 16 to 19 of R4
MOVNE R9 , #1
CMP R9 , #0
MOVEQ R0 , #&20
ORRNE R0 , R8 , #&30
SWI OS_WriteC
ANDS R8 , R11 , R4, LSR#12 \ extract just the BCD in bits 12 to 15 of R4
MOVNE R9 , #1
CMP R9 , #0
MOVEQ R0 , #&20
ORRNE R0 , R8 , #&30
SWI OS_WriteC
ANDS R8 , R11 , R4, LSR#8 \ extract just the BCD in bits 8 to 11 of R4
MOVNE R9 , #1
CMP R9 , #0
MOVEQ R0 , #&20
ORRNE R0 , R8 , #&30
SWI OS_WriteC
ANDS R8 , R11 , R4, LSR#4 \ extract just the BCD in bits 4 to 7 of R4
MOVNE R9 , #1
CMP R9 , #0
MOVEQ R0 , #&20
ORRNE R0 , R8 , #&30
SWI OS_WriteC
\ have reached the l.s. BCD - so will always output a digit, never a space
AND R8 , R11 , R4 \ extract just the BCD in bits 0 to 3 of R4
ORR R0 , R8 , #&30 \ digits 0 to 9 all ready for output
SWI OS_WriteC \ output the byte in R0
MOV R0 , #&13 \ carriage return
SWI OS_WriteC
MOV R0 , #&10 \ line feed
SWI OS_WriteC
\ there is no need for a branch instruction here
\ instead just fall through to the next increment
.bcd_32bits_loop_vn02
ADD R4 , R4 , #1 \ increment the l.s. BCD in bits 0 to 3
AND R8 , R4 , #&F \ extract just the BCD nibble after increment
CMP R8 , #10 \ has it reached 10?
\ if not then about to branch to the display code
BLT bcd_32bits_display_previous_number_vn02
\ have reached 10
ANDEQ R4 , R4 , R10 \ R10 contains &FFFFFFF0 so the BCD is set to 0
\ but now need to add in the carry to the next BCD
\ I have noticed that the EQ is superfluous here
\ but it does no harm
\ now work with the nibble in bits 4 to 7 (bit 31 is m.s. and bit 0 is l.s.)
MOV R4 , R4 , ROR #4 \ rotate R4 right by 4 bits
ADD R4 , R4 , #1 \ add in the carry
AND R8 , R4 , #&F \ extract just the BCD nibble after carry added
CMP R8 , #10 \ has it reached 10?
\ if less than 10 then rotate back to correct place
\ then branch to the display code
MOVLT R4 , R4 , ROR #28 \ finished adding in carry - rotate R4 right by 32-4=28 bits
BLT bcd_32bits_display_previous_number_vn02
\ yet another carry
ANDEQ R4 , R4 , R10 \ R10 contains &FFFFFFF0 so the BCD is set to 0
\ but now need to add in the carry to the next BCD
\ now work with the nibble in bits 8 to 11 (bit 31 is m.s. and bit 0 is l.s.)
MOV R4 , R4 , ROR #4 \ rotate R4 right by 4 bits
ADD R4 , R4 , #1 \ add in the carry
AND R8 , R4 , #&F \ extract just the BCD nibble after carry added
CMP R8 , #10 \ has it reached 10?
\ if less than 10 then rotate back to correct place
\ then branch to the display code
MOVLT R4 , R4 , ROR #24 \ finished adding in carry - rotate R4 right by 32-8=24 bits
BLT bcd_32bits_display_previous_number_vn02
\ yet another carry
ANDEQ R4 , R4 , R10
\ now work with the nibble in bits 12 to 15 (bit 31 is m.s. and bit 0 is l.s.)
MOV R4 , R4 , ROR #4
ADD R4 , R4 , #1
AND R8 , R4 , #&F
CMP R8 , #10
MOVLT R4 , R4 , ROR #20 \ finished adding in carry - rotate R4 right by 32-12=20 bits
BLT bcd_32bits_display_previous_number_vn02
\ yet another carry
ANDEQ R4 , R4 , R10
\ now work with the nibble in bits 16 to 19 (bit 31 is m.s. and bit 0 is l.s.)
MOV R4 , R4 , ROR #4
ADD R4 , R4 , #1
AND R8 , R4 , #&F
CMP R8 , #10
MOVLT R4 , R4 , ROR #16 \ finished adding in carry - rotate R4 right by 32-16=16 bits
BLT bcd_32bits_display_previous_number_vn02
\ yet another carry
ANDEQ R4 , R4 , R10
\ now work with the nibble in bits 20 to 23 (bit 31 is m.s. and bit 0 is l.s.)
MOV R4 , R4 , ROR #4
ADD R4 , R4 , #1
AND R8 , R4 , #&F
CMP R8 , #10
MOVLT R4 , R4 , ROR #12 \ finished adding in carry - rotate R4 right by 32-20=12 bits
BLT bcd_32bits_display_previous_number_vn02
\ yet another carry
ANDEQ R4 , R4 , R10
\ now work with the nibble in bits 24 to 27 (bit 31 is m.s. and bit 0 is l.s.)
MOV R4 , R4 , ROR #4
ADD R4 , R4 , #1
AND R8 , R4 , #&F
CMP R8 , #10
MOVLT R4 , R4 , ROR #8 \ finished adding in carry - rotate R4 right by 32-24=8 bits
BLT bcd_32bits_display_previous_number_vn02
\ yet another carry
ANDEQ R4 , R4 , R10
\ now work with the nibble in bits 28 to 31 (bit 31 is m.s. and bit 0 is l.s.)
MOV R4 , R4 , ROR #4
ADD R4 , R4 , #1
AND R8 , R4 , #&F
CMP R8 , #10
MOVLT R4 , R4 , ROR #4 \ finished adding in carry - rotate R4 right by 32-28=4 bits
BLT bcd_32bits_display_previous_number_vn02
\ yet another carry
ANDEQ R4 , R4 , R10
\ to continue the carry needs to be added to the next register (probably R5) if more than 8 BCD are required
\ if yet more than 16 BCD then continue to the next register (R6)
\ the extra code required will be as above but using R5 (or R6) instead of R4
MOVS PC , R14 \ return
 
</pre>
 
=={{header|ArnoldC}}==
<langsyntaxhighlight lang="arnoldc">IT'S SHOWTIME
HEY CHRISTMAS TREE n
YOU SET US UP @NO PROBLEMO
Line 225 ⟶ 511:
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED</langsyntaxhighlight>
 
=={{header|Arturo}}==
<langsyntaxhighlight lang="rebol">i:0
while ø [
print i
inc 'i
]</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
This uses traytip to show the results. A msgbox, tooltip, or fileappend could also be used.
<syntaxhighlight lang="autohotkey">x=0
<lang AutoHotkey>x=0
Loop
TrayTip, Count, % ++x</langsyntaxhighlight>
 
=={{header|AWK}}==
<langsyntaxhighlight lang="awk">BEGIN {
for( i=0; i != i + 1; i++ )
print( i )
}</langsyntaxhighlight>
 
Awk uses floating-point numbers. This loop terminates when <code>i</code> becomes too large for integer precision. With IEEE doubles, this loop terminates when <code>i</code> reaches <code>2 ^ 53</code>.
Line 251 ⟶ 537:
Integers in Axe are limited to 16 bits, or a maximum of 65535. This script will run infinitely until either the variable overflows or a key is pressed.
 
<langsyntaxhighlight lang="axe">While getKey(0)
End
0→I
Line 257 ⟶ 543:
Disp I▶Dec,i
I++
EndIf I=0</langsyntaxhighlight>
 
=={{header|BASIC}}==
{{works with|ZX Spectrum Basic}}
<langsyntaxhighlight lang="zxbasic">10 LET A = 0
20 LET A = A + 1
30 PRINT A
40 GO TO 20</langsyntaxhighlight>
{{works with|QBasic}}
<langsyntaxhighlight lang="qbasic">A = 0
DO: A = A + 1: PRINT A: LOOP 1</langsyntaxhighlight>
 
=={{header|BASIC256}}==
<langsyntaxhighlight BASIC256lang="basic256">i = 1
 
do
print i
i += 1
until i = 0</langsyntaxhighlight>
 
 
=={{header|Batch File}}==
Variables are limited to 32bit integer, capable of a maximum value of <code>2,147,483,647</code>
<langsyntaxhighlight lang="dos">
@echo off
set number=0
Line 287 ⟶ 573:
echo %number%
goto loop
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 305 ⟶ 591:
{{works with|BBC BASIC for Windows}}
Native version, limited to 53-bit integers (maximum output 9007199254740992):
<langsyntaxhighlight lang="bbcbasic"> *FLOAT 64
REPEAT
i += 1
PRINT TAB(0,0) i;
UNTIL FALSE</langsyntaxhighlight>
Version using Huge Integer Math and Encryption library (up to 2^31 bits, but this program limited to 65535 decimal digits because of maximum string length):
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"HIMELIB"
PROC_himeinit("")
reg% = 1
Line 319 ⟶ 605:
SYS `hi_Incr`, ^reg%, ^reg%
PRINT TAB(0,0) FN_higetdec(reg%);
UNTIL FALSE</langsyntaxhighlight>
 
=={{header|bc}}==
<syntaxhighlight lang ="bc">while (++i) i</langsyntaxhighlight>
 
=={{header|beeswax}}==
Using an ordinary loop structure:
<langsyntaxhighlight lang="beeswax"> qNP<
_1>{d</langsyntaxhighlight>
 
Using a jump instruction:
<syntaxhighlight lang ="beeswax">_1F6~@{PN@J</langsyntaxhighlight>
 
Numbers in beeswax are unsigned 64-bit integers, so after reaching 2^64-1 the counter wraps around to 0.
Line 339 ⟶ 625:
Also note that the range of values written to the code page or 'playfield' is often much smaller - frequently only supporting 8 bits, sometimes signed, sometimes unsigned.
 
<langsyntaxhighlight lang="befunge">1+:0`!#@_:.55+,</langsyntaxhighlight>
 
=={{header|BQN}}==
 
While the input is lesser than or equal to infinity, print, then increment.
<langsyntaxhighlight lang="bqn">_while_ ← {𝔽⍟𝔾∘𝔽_𝕣_𝔾∘𝔽⍟𝔾𝕩}
(1+•Show) _while_ (≤⟜∞) 1</langsyntaxhighlight>
 
=={{header|Bracmat}}==
{{trans|Ruby}}
Bracmat uses big numbers. Numbers are stored with a radix 10, each decimal digit occupying one byte. When multiplying or dividing, numbers are temporarily converted to radix 10000 (32-bit systems: 1 digit occupies two bytes) or radix 100000000 (64-bit systems: 1 digit occupies four bytes) to speed up the computation.
<syntaxhighlight lang="text">0:?n&whl'out$(1+!n:?n)</langsyntaxhighlight>
 
=={{header|Brainf***}}==
This program assumes that decrementing past zero wraps around, but it doesn't rely on cell size, other than that a cell can hold at least six bits. It also assumes the ASCII character set. This is an arbitrarily large number implementation.
<langsyntaxhighlight lang="brainf***">++++++++++>>>+[[->>+<[+>->+<<---------------------------------------
-------------------[>>-<++++++++++<[+>-<]]>[-<+>]<++++++++++++++++++
++++++++++++++++++++++++++++++>]<[<]>>[-<+++++++++++++++++++++++++++
++++++++++++++++++++++>]>]>[>>>]<<<[.<<<]<.>>>+]</langsyntaxhighlight>
 
This modification of the previous program will print out 1 to the maximum cell value, still assuming wrapping. On many implementations, this will print out 1-255.
<langsyntaxhighlight lang="brainf***">++++++++++>>-[>+[->>+<[+>->+<<--------------------------------------
--------------------[>>-<++++++++++<[+>-<]]>[-<+>]<+++++++++++++++++
+++++++++++++++++++++++++++++++>]<[<]>>[-<++++++++++++++++++++++++++
+++++++++++++++++++++++>]>]>[>>>]<<<[.<<<]<.>>-]</langsyntaxhighlight>
 
This program can count in any base counting system under 256. '''Note:''' Change the characters in quotes equal to the base counting system you want to use.
<langsyntaxhighlight lang="brainf***">+[<<+>>[[<<"-----------"["+++++++++++"<]>]>[<<<<+>>+>>[>>]<]<]>>[>>]<<]</langsyntaxhighlight>
 
=={{header|Brat}}==
<langsyntaxhighlight lang="brat">i = 1
 
loop {
p i
i = i + 1
}</langsyntaxhighlight>
 
=={{header|Burlesque}}==
 
<langsyntaxhighlight lang="burlesque">
1R@
</syntaxhighlight>
</lang>
 
=={{header|C}}==
Prints from 1 to max unsigned integer (usually 2**32 -1), then stops.
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int main()
Line 392 ⟶ 678:
 
return 0;
}</langsyntaxhighlight>
 
==={{libheader|GMP}}===
This one never stops. It's not even likely that you'll run out of memory before you run out of patience. <langsyntaxhighlight lang="c">#include <gmp.h>
 
int main()
Line 408 ⟶ 694:
 
return 0;
}</langsyntaxhighlight>
 
==={{libheader|OpenSSL}}===
OpenSSL provides arbitrarily large integers.
 
<langsyntaxhighlight lang="c">#include <openssl/bn.h> /* BN_*() */
#include <openssl/err.h> /* ERR_*() */
#include <stdio.h> /* fprintf(), puts() */
Line 441 ⟶ 727:
}
/* NOTREACHED */
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
using System.Numerics;
 
Line 457 ⟶ 743:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <cstdint>
#include <iostream>
#include <limits>
Line 470 ⟶ 756:
while (i < std::numeric_limits<decltype(i)>::max())
std::cout << ++i << '\n';
}</langsyntaxhighlight>
<!--
<langsyntaxhighlight lang="cpp">// Using the proposed unbounded integer library
 
#include <iostream>
Line 490 ⟶ 776:
// Do nothing
}
}</langsyntaxhighlight>
-->
 
=={{header|ChucK}}==
Math.INT_MAX is a constant value that represents the greater integer, 32 bit , 64 bit systems.
<syntaxhighlight lang="text">
for(1 => int i; i < Math.INT_MAX; i ++)
{
<<< i >>>;
}
</syntaxhighlight>
</lang>
 
=={{header|Clean}}==
In Clean this example has a limit of basically 2147483648.
<langsyntaxhighlight Cleanlang="clean">module IntegerSequence
 
import StdEnv
 
Start = [x \\ x <- [1..]]</langsyntaxhighlight>
 
Output:
Line 514 ⟶ 800:
 
=={{header|Clojure}}==
<langsyntaxhighlight Clojurelang="clojure">(map println (next (range)))</langsyntaxhighlight>
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">% This iterator will generate all integers until the built-in type
% overflows. It is a signed machine-sized integer; so 64 bits on
% a modern machine. After that it will raise an exception.
Line 534 ⟶ 820:
stream$putl(po, int$unparse(i))
end
end start_up </langsyntaxhighlight>
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Int-Sequence.
 
Line 552 ⟶ 838:
 
GOBACK
.</langsyntaxhighlight>
 
=={{header|CoffeeScript}}==
Like with most languages, counting is straightforward in CoffeeScript, so the program below tries to handle very large numbers. See the comments for starting the sequence from 1.
 
<langsyntaxhighlight lang="coffeescript">
# This very limited BCD-based collection of functions
# makes it easy to count very large numbers. All arrays
Line 593 ⟶ 879:
console.log BcdInteger.render big_int
big_int = BcdInteger.succ big_int
</syntaxhighlight>
</lang>
 
output
<syntaxhighlight lang="text">
> coffee foo.coffee | head -5
199999999999999999999999999999999999999999999999999999
Line 603 ⟶ 889:
200000000000000000000000000000000000000000000000000002
200000000000000000000000000000000000000000000000000003
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
 
<langsyntaxhighlight lang="lisp">(loop for i from 1 do (print i))</langsyntaxhighlight>
 
If your compiler does tail call elimination (note: this has absolutely no advantage over normal loops):
<langsyntaxhighlight lang="lisp">(defun pp (x) (pp (1+ (print x))))
(funcall (compile 'pp) 1) ; it's less likely interpreted mode will eliminate tails</langsyntaxhighlight>
 
=={{header|Component Pascal}}==
BlackBox Component Builder
<langsyntaxhighlight lang="oberon2">
MODULE IntegerSequence;
IMPORT StdLog;
Line 630 ⟶ 916:
 
END IntegerSequence.
</syntaxhighlight>
</lang>
Execute: ^Q IntegerSequence.Do<br/>
Output:
Line 639 ⟶ 925:
=={{header|Computer/zero Assembly}}==
This program counts up to 255 in the accumulator, after which it starts again from zero.
<langsyntaxhighlight lang="czasm">start: ADD one
JMP start
one: 1</langsyntaxhighlight>
 
=={{header|Cowgol}}==
Line 648 ⟶ 934:
This program will count up to 2^32-1, and then stop.
 
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
var n: uint32 := 1;
Line 655 ⟶ 941:
print_nl();
n := n + 1;
end loop;</langsyntaxhighlight>
 
The following program will keep going until it runs out of memory, using one byte per digit.
 
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub print_back(s: [uint8]) is
Line 703 ⟶ 989:
infnum := incr(infnum);
print_back(infnum);
end loop;</langsyntaxhighlight>
 
=={{header|Crystal}}==
Will run as long as enough memory to represent numbers.
<langsyntaxhighlight lang="ruby">require "big"
 
(1.to_big_i ..).each { |i| puts i } </langsyntaxhighlight>
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio, std.bigint;
 
void main() {
Line 718 ⟶ 1,004:
while (true)
writeln(++i);
}</langsyntaxhighlight>
Alternative:
<langsyntaxhighlight lang="d">import std.stdio, std.traits, std.bigint, std.string;
 
void integerSequence(T)() if (isIntegral!T || is(T == BigInt)) {
Line 755 ⟶ 1,041:
default: writeln("\nBye bye!"); break;
}
}</langsyntaxhighlight>
 
=={{header|Dc}}==
<syntaxhighlight lang Dc="dc">1[p1+lpx]dspx</langsyntaxhighlight>
 
=={{header|DCL}}==
<langsyntaxhighlight DCLlang="dcl">$ i = 1
$ loop:
$ write sys$output i
$ i = i + 1
$ goto loop</langsyntaxhighlight>
{{out}}
<pre>1
Line 782 ⟶ 1,068:
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">program IntegerSequence;
 
{$APPTYPE CONSOLE}
Line 791 ⟶ 1,077:
for i := 1 to High(i) do
WriteLn(i);
end.</langsyntaxhighlight>
 
=={{header|DWScript}}==
High(i) returns the maximum supported value, typically, it is the highest signed 64 bit integer.
<langsyntaxhighlight lang="delphi">
var i: Integer;
 
for i:=1 to High(i) do
PrintLn(i);
</syntaxhighlight>
</lang>
 
=={{header|Dyalect}}==
 
<langsyntaxhighlight lang="dyalect">var n = 0
while true {
n += 1
print(n)
}</langsyntaxhighlight>
 
=={{header|Déjà Vu}}==
<langsyntaxhighlight lang="dejavu">1
 
while /= -- dup dup:
Line 817 ⟶ 1,103:
++
 
drop</langsyntaxhighlight>
 
This continues to print numbers until double precision IEEE 754 cannot represent adjacent integers any more (9007199254740992, to be exact).
Line 825 ⟶ 1,111:
=={{header|E}}==
 
<langsyntaxhighlight lang="e">for i in int > 0 { println(i) }</langsyntaxhighlight>
 
=={{header|EasyLang}}==
 
<syntaxhighlight lang="easylang">
max = pow 2 53
repeat
print i
if i = 10
print "."
print "."
i = max - 10
.
until i = max
i += 1
.
</syntaxhighlight>
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang="scheme">
(lib 'bigint) ;; arbitrary length integers
(for ((n (in-naturals))) (writeln n))
</syntaxhighlight>
</lang>
 
=={{header|EDSAC order code}}==
<langsyntaxhighlight lang="edsac">[ Integer sequence
================
Line 855 ⟶ 1,157:
P0D [ constant: 1 ]
EZPF [ begin at load point ]</langsyntaxhighlight>
 
=={{header|Eiffel}}==
<langsyntaxhighlight lang="eiffel">
class
APPLICATION
Line 881 ⟶ 1,183:
number:INTEGER_64
end
</syntaxhighlight>
</lang>
 
=={{header|Elena}}==
ELENA 4.x :
<langsyntaxhighlight lang="elena">import extensions;
public program()
Line 896 ⟶ 1,198:
i += 1u
}
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">Stream.iterate(1, &(&1+1)) |> Enum.each(&(IO.puts &1))</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)
(message "%d" (1+ i)))</langsyntaxhighlight>
 
=={{header|Erlang}}==
 
<langsyntaxhighlight lang="erlang"> F = fun(FF, I) -> io:format("~p~n", [I]), FF(FF, I + 1) end, F(F,0). </langsyntaxhighlight>
 
=={{header|ERRE}}==
<syntaxhighlight lang="text">
.............
A%=0
Line 920 ⟶ 1,222:
END LOOP
.............
</syntaxhighlight>
</lang>
% is integer-type specificator. Integer type works on 16-bit signed numbers (reserved constant MAXINT is 32767). Beyond this limit execution will give Runtime error #6 (overflow).
 
=={{header|Euphoria}}==
<langsyntaxhighlight lang="euphoria">integer i
i = 0
while 1 do
? i
i += 1
end while</langsyntaxhighlight>
 
=={{header|F_Sharp|F#}}==
 
<langsyntaxhighlight lang="fsharp">// lazy sequence of integers starting with i
let rec integers i =
seq { yield i
yield! integers (i+1) }
 
Seq.iter (printfn "%d") (integers 1)</langsyntaxhighlight>
 
lazy sequence of int32 starting from 0
<langsyntaxhighlight lang="fsharp">let integers = Seq.initInfinite id</langsyntaxhighlight>
 
lazy sequence of int32 starting from n
<langsyntaxhighlight lang="fsharp">let integers n = Seq.initInfinite ((+) n)</langsyntaxhighlight>
 
lazy sequence (not necessarily of int32) starting from n (using unfold anamorphism)
<langsyntaxhighlight lang="fsharp">let inline numbers n =
Seq.unfold (fun n -> Some (n, n + LanguagePrimitives.GenericOne)) n</langsyntaxhighlight>
<div>
> numbers 0 |> Seq.take 10;;
Line 983 ⟶ 1,285:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USE: lists.lazy
1 lfrom [ . ] leach</langsyntaxhighlight>
 
=={{header|Fantom}}==
 
<langsyntaxhighlight lang="fantom">
class Main
{
Line 1,001 ⟶ 1,303:
}
}
</syntaxhighlight>
</lang>
 
Fantom's integers are 64-bit signed, and so the numbers will return to 0 and continue again, if you wait long enough!
Line 1,007 ⟶ 1,309:
 
=={{header|Fermat}}==
<langsyntaxhighlight lang="fermat">n:=0;
while 1 do !n;!' '; n:=n+1 od</langsyntaxhighlight>
 
=={{header|Fish}}==
Since there aren't really libraries in Fish and I wouldn't know how to program arbitarily large integers, so here's an example that just goes on until the interpreter's number limit:
<langsyntaxhighlight Fishlang="fish">0>:n1+v
^o" "<</langsyntaxhighlight>
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">: ints ( -- )
0 begin 1+ dup cr u. dup -1 = until drop ;</langsyntaxhighlight>
 
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<langsyntaxhighlight lang="fortran">program Intseq
implicit none
Line 1,033 ⟶ 1,335:
n = n + 1
end do
end program</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
' FB does not natively support arbitrarily large integers though support can be added
Line 1,049 ⟶ 1,351:
Loop Until i = 0 ' will wrap back to 0 when it reaches 4,294,967,296
 
Sleep</langsyntaxhighlight>
 
=={{header|Frink}}==
All of Frink's numbers can be arbitrarily-sized:
<syntaxhighlight lang="frink">
<lang Frink>
i=0
while true
Line 1,060 ⟶ 1,362:
i = i + 1
}
</syntaxhighlight>
</lang>
 
=={{header|FunL}}==
The following has no limit since FunL has arbitrary size integers.
 
<langsyntaxhighlight lang="funl">for i <- 1.. do println( i )</langsyntaxhighlight>
 
=={{header|Futhark}}==
Line 1,072 ⟶ 1,374:
accepts an input indicating how many integers to generate. It encodes the size of the returned array in its type.
 
<syntaxhighlight lang="futhark">
<lang Futhark>
fun main(n: int): [n]int = iota n
</syntaxhighlight>
</lang>
 
 
 
=={{header|FutureBasic}}==
ULLONG_MAX = 18446744073709551615. So this will crash long before getting there!
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
UInt64 i = 1
 
while ( i < ULLONG_MAX )
NSLog( @"%llu\n", i )
i++
wend
 
// NSLog( @"Maximum Unsigned long long: %llu", ULLONG_MAX )
 
HandleEvents
</syntaxhighlight>
 
 
 
=={{header|GAP}}==
<langsyntaxhighlight lang="gap">InfiniteLoop := function()
local n;
n := 1;
Line 1,087 ⟶ 1,410:
 
# Prepare some coffee
InfiniteLoop();</langsyntaxhighlight>
 
=={{header|Go}}==
Size of <tt>int</tt> type is implementation dependent. After the maximum positive value, it rolls over to maximum negative, without error. Type <tt>uint</tt> will roll over to zero.
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 1,099 ⟶ 1,422:
fmt.Println(i)
}
}</langsyntaxhighlight>
The <tt>big.Int</tt> type does not roll over and is limited only by available memory, or practically, by whatever external factor halts CPU execution: human operator, lightning storm, CPU fan failure, heat death of universe, etc.
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,113 ⟶ 1,436:
fmt.Println(i)
}
}</langsyntaxhighlight>
 
=={{header|Gridscript}}==
<langsyntaxhighlight lang="gridscript">
#INTEGER SEQUENCE.
 
Line 1,128 ⟶ 1,451:
(9,1):INCREMENT
(11,1):GOTO 0
</syntaxhighlight>
</lang>
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">// 32-bit 2's-complement signed integer (int/Integer)
for (def i = 1; i > 0; i++) { println i }
 
Line 1,138 ⟶ 1,461:
 
// Arbitrarily-long binary signed integer (BigInteger)
for (def i = 1g; ; i+=1g) { println i }</langsyntaxhighlight>
 
=={{header|GUISS}}==
Line 1,144 ⟶ 1,467:
Graphical User Interface Support Script makes use of installed programs. There are no variables, no loop structures and no jumps within the language so iteration is achieved by repetative instructions. In this example, we will just use the desktop calculator and keep adding one to get a counter. We stop after counting to ten in this example.
 
<langsyntaxhighlight lang="guiss">Start,Programs,Accessories,Calculator,
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals],
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals],
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals],
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals],
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals]</langsyntaxhighlight>
 
=={{header|GW-BASIC}}==
<langsyntaxhighlight lang="gwbasic">10 A#=1
20 PRINT A#
30 A#=A#+1
40 GOTO 20</langsyntaxhighlight>
 
=={{header|Haskell}}==
<syntaxhighlight lang ="haskell">mapM_ print [1..]</langsyntaxhighlight>
 
Or less imperatively:
 
<langsyntaxhighlight lang="haskell">putStr $ unlines $ map show [1..]</langsyntaxhighlight>
 
=={{header|HolyC}}==
Prints from 1 to max unsigned 64 bit integer (2**64 -1), then stops.
<langsyntaxhighlight lang="holyc">U64 i = 0;
while (++i) Print("%d\n", i);
</syntaxhighlight>
</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
Icon and Unicon support large integers by default. The built-in generator seq(i,j) yields the infinite sequence i, i+j, i+2*j, etc. Converting the results to strings for display will likely eat your lunch before the sequence will take its toll.
 
<langsyntaxhighlight Iconlang="icon">procedure main()
every write(seq(1)) # the most concise way
end</langsyntaxhighlight>
 
=={{header|IS-BASIC}}==
<langsyntaxhighlight ISlang="is-BASICbasic">100 FOR I=1 TO INF
110 PRINT I;
120 NEXT</langsyntaxhighlight>
 
INF = 9.999999999E62
Line 1,187 ⟶ 1,510:
The following will count indefinitely but once the 32-bit (or 64-bit depending on J engine version) limit is reached, the results will be reported as floating point values (which would immediately halt on 64 bit J and halt with the 53 bit precision limit is exceeded on 32 bit J). Since that could take many, many centuries, even on a 32 bit machine, more likely problems include the user dying of old age and failing to pay the electric bill resulting in the machine being powered off.
 
<langsyntaxhighlight lang="j"> count=: (smoutputecho ] >:)^:_</langsyntaxhighlight>
 
The above works with both fixed sized integers and floating point numbers (fixed sized integers are automatically promoted to floating point, if they overflow), but also works with extended precision integers (which will not overflow, unless they get so large that they cannot be represented in memory, but that should exceed lifetime of the universe, let alone lifetime of the computer).
 
This adds support for extended precision (in that it converts non-extended precision arguments to extended precision arguments) and will display integers to ∞ (or at least until the machine is turned off or interrupted or crashes).
<langsyntaxhighlight lang="j"> count=: (smoutputecho ] >:)@x:^:_</langsyntaxhighlight>
 
=={{header|Jakt}}==
Jakt's default integer type is i64. Specifying 1u64 allows it to (theoretically) count to 2^64 - 2 (The range has an implicit exclusive upper bound of 2^64 - 1).
<syntaxhighlight lang="jakt">
fn main() {
for i in (1u64..) {
println("{}", i)
}
}
</syntaxhighlight>
 
=={{header|Java}}==
Long limit:
<syntaxhighlight lang ="java">public class Count{
public static voidclass main(String[]Count args){
public static void main(String[] args) {
for(long i = 1; ;i++) System.out.println(i);
}
}
}</lang>
</syntaxhighlight>
"Forever":
<syntaxhighlight lang="java">
<lang java>import java.math.BigInteger;
import java.math.BigInteger;
 
public class Count {
public static void main(String[] args) {
for(BigInteger i = BigInteger.ONE; ;i = i.add(BigInteger.ONE)) System.out.println(i);
}
}
}</lang>
</syntaxhighlight>
 
==={{libheader|Stream}}===
{{works with|OpenJDK|8}}
This solution leverages the Stream API to create declarative integer sequences, which is arguably more readable than the unbound for loop approach.
 
Overflow-unsafe code using the long primitive:
<syntaxhighlight lang="java">
import java.util.stream.LongStream;
 
public class Count {
public static void main(String[] args) {
LongStream.iterate(1, l -> l + 1)
.forEach(System.out::println);
}
}
</syntaxhighlight>
 
BigInteger solution with arbitrary size integers:
<syntaxhighlight lang="java">
import static java.math.BigInteger.ONE;
 
import java.util.stream.Stream;
 
public class Count {
public static void main(String[] args) {
Stream.iterate(ONE, i -> i.add(ONE))
.forEach(System.out::println);
}
}
</syntaxhighlight>
 
=={{header|JavaScript}}==
This code is accurate up to 2^53 where it will be stuck an 2^53 because a IEEE 64-bit double can not represent 2^53 + 1.
<langsyntaxhighlight lang="javascript">var i = 0;
 
while (true)
document.write(++i + ' ');</langsyntaxhighlight>
This example uses a BigInt[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt] literal to support arbitrary large integers.
<langsyntaxhighlight lang="javascript">var i = 0n;
 
while (true)
document.write(++i + ' ');</langsyntaxhighlight>
 
=={{header|Joy}}==
<langsyntaxhighlight lang="joy">
1 [0 >] [dup put succ] while pop.</langsyntaxhighlight>
 
Counting stops at <code>maxint</code>, which is: 2147483647
 
=={{header|jq}}==
Currently,The Go implementation of jq does not support infinitearbitrary-precision integer arithmetic, but verycurrently large(2024) integersthe areC convertedimplementation toof floating-point numbers, so the followingjq will continueresort to generatefloating-point integersarithmetic (beginningfor withvery 0)large indefinitely in recent versions of jq that have tail recursion optimization:integers.
<lang jq>def iota: ., (. + 1 | iota);
0 | iota</lang>In versions of jq which have <tt>while</tt>, one could also write:<lang jq>0 | while(true;. + 1)</lang>This idiom is likely to be more useful as <tt>while</tt> supports <tt>break</tt>.
 
Consider, for example:
Another technique would be to use <tt>recurse</tt>:
<lang jq>0 | recurse(. + 1)</lang>For generating integers, the generator, <tt>range(m;n)</tt>, is more likely to be useful in practice; if m and n are integers, it generates integers from m to n-1, inclusive.
 
<syntaxhighlight lang="jq">0 | recurse(. + 1)</syntaxhighlight>
 
Using gojq, this will indefinitely generate a stream of integers beginning with 0, but jq (the C implementation) will eventually lose precision.
For generating integers, the built-in function <tt>range(m;n)</tt> is more likely to be useful in practice; if m and n are integers, it generates integers from m to n-1, inclusive. `range(m; infinite)` is also valid for any integer.
 
The C implementation of jq supports tail recursion optimization, and thus the following tail-recursive definition could be used:
<syntaxhighlight lang="jq">def iota: ., (. + 1 | iota);
0 | iota</syntaxhighlight>
 
One could also write:<syntaxhighlight lang="jq">0 | while(true; . + 1)</syntaxhighlight>
 
Integers can of course also be represented by strings of decimal digits, and if this representation is satisfactory, a stream of consecutive integers thus represented can be generated using the same technique as is employed on the
Line 1,241 ⟶ 1,616:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">i = zero(BigInt) # or i = big(0)
while true
println(i += 1)
end</langsyntaxhighlight>
The built-in <code>BigInt</code> type is an arbitrary precision integer (based on the GMP library), so the value of <code>i</code> is limited only by available memory. To use (much faster) hardware fixed-width integer types, use e.g. <code>zero(Int32)</code> or <code>zero(Int64)</code>. (Initializing <code>i = 0</code> will use fixed-width integers that are the same size as the hardware address width, e.g. 64-bit on a 64-bit machine.)
 
=={{header|K}}==
<langsyntaxhighlight lang="k"> {`0:"\n",$x+:1;x}/1</langsyntaxhighlight>
 
Using a <code>while</code> loop:
 
<langsyntaxhighlight lang="k"> i:0; while[1;`0:"\n",$i+:1]</langsyntaxhighlight>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">import java.math.BigInteger
 
// version 1.0.5-2
Line 1,269 ⟶ 1,644:
n += BigInteger.ONE
}
}</langsyntaxhighlight>
 
=={{header|Lambdatalk}}==
The long_add primitive allow counting beyond the javascript numbers limits, depending on the system memory.
<langsyntaxhighlight lang="scheme">
{def infinite_set
{lambda {:i}
Line 1,283 ⟶ 1,658:
{infinite_set 0}
-> 0 1 2 3 ... forever
</syntaxhighlight>
</lang>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang">
# LONG limit (64 bits signed)
$l = 1L
loop {
fn.println($l)
$l += 1
}
</syntaxhighlight>
 
=={{header|Lang5}}==
<langsyntaxhighlight lang="lang5">0 do dup . 1 + loop</langsyntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">local(number = 1)
while(#number > 0) => {^
#number++
' '
//#number > 100 ? #number = -2 // uncomment this row if you want to halt the run after proving concept
^}</langsyntaxhighlight>
This will run until you exhaust the system resources it's run under.
 
=={{header|Liberty BASIC}}==
Liberty BASIC handles extremely large integers. The following code was halted by user at 10,000,000 in test run.
<langsyntaxhighlight lang="lb"> while 1
i=i+1
locate 1,1
Line 1,305 ⟶ 1,691:
scan
wend
</langsyntaxhighlight>
 
=={{header|Limbo}}==
The int (32 bits) and big (64 bits) types are both signed, so they wrap around. This version uses the infinite precision integer library:
 
<langsyntaxhighlight Limbolang="limbo">implement CountToInfinity;
 
include "sys.m"; sys: Sys;
Line 1,333 ⟶ 1,719:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Lingo}}==
<langsyntaxhighlight lang="lingo">i = 1
repeat while i>0
put i
i = i+1
end repeat</langsyntaxhighlight>
 
Lingo uses signed 32 bit integers, so max. supported integer value is 2147483647:
<langsyntaxhighlight lang="lingo">put the maxInteger
-- 2147483647</langsyntaxhighlight>
 
Beyond this limit values behave like negative numbers:
<langsyntaxhighlight lang="lingo">put the maxInteger+1
-- -2147483648
put the maxInteger+2
-- -2147483647</langsyntaxhighlight>
Up to the (quite high) number where floats (double-precission) start rounding, floats can be used to exceed the integer limit:
<langsyntaxhighlight lang="lingo">the floatPrecision = 0 -- forces floats to be printed without fractional digits
 
put float(the maxInteger)+1
Line 1,369 ⟶ 1,755:
-- 2
-- 3
-- ...</langsyntaxhighlight>
 
=={{header|LLVM}}==
{{trans|C}}
<langsyntaxhighlight lang="llvm">; This is not strictly LLVM, as it uses the C library function "printf".
; LLVM does not provide a way to print values, so the alternative would be
; to just load the string into memory, and that would be boring.
Line 1,407 ⟶ 1,793:
}
 
attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }</langsyntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">
i = 1
 
Line 1,421 ⟶ 1,807:
i = i + 1
end
</syntaxhighlight>
</lang>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
\\ easy way
a=1@
Line 1,448 ⟶ 1,834:
\\ this flag reset to false before restart.
{loop : Print a : a++}
</syntaxhighlight>
</lang>
 
=={{header|Maple}}==
Maple has arbitrary-precision integers so there are no built-in limits on the size of the integers represented.
 
<langsyntaxhighlight Maplelang="maple">for n do
print(n)
end do;</langsyntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Built in arbitrary precision support means the following will not overflow.
<syntaxhighlight lang="mathematica">
<lang Mathematica>
x = 1;
Monitor[While[True, x++], x]
</syntaxhighlight>
</lang>
 
=={{header|MATLAB}} / {{header|Octave}}==
 
<langsyntaxhighlight Matlablang="matlab"> a = 1; while (1) printf('%i\n',a); a=a+1; end; </langsyntaxhighlight>
 
Typically, numbers are stored as double precision floating point numbers, giving accurate integer values up to about 2^53=bitmax('double')=9.0072e+15. Above this limit, round off errors occur. This limitation can be overcome by defining the numeric value as type int64 or uint64
 
<langsyntaxhighlight Matlablang="matlab"> a = uint64(1); while (1) printf('%i\n',a); a=a+1; end; </langsyntaxhighlight>
 
This will run up to 2^64 and then stop increasing, there will be no overflow.
Line 1,485 ⟶ 1,871:
Matlab and Octave recommend vectorizing the code, one might pre-allocate the sequence up to a specific N.
 
<langsyntaxhighlight Matlablang="matlab"> N = 2^30; printf('%d\n', 1:N); </langsyntaxhighlight>
 
The main limitation is the available memory on your machine. The standard version of Octave has a limit that a single data structure can hold at most 2^31 elements. In order to overcome this limit, Octave must be compiled with "./configure --enable-64", but this is currently not well supported.
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">for i do disp(i);</langsyntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.19.3}}
min's integers are 64-bit signed. This will eventually overflow.
<langsyntaxhighlight lang="min">0 (dup) () (puts succ) () linrec</langsyntaxhighlight>
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">1 П4 ИП4 С/П КИП4 БП 02</langsyntaxhighlight>
 
=={{header|ML/I}}==
<langsyntaxhighlight MLlang="ml/Ii">MCSKIP "WITH" NL
"" Integer sequence
"" Will overflow when it reaches implementation-defined signed integer limit
Line 1,511 ⟶ 1,897:
MCGO L1
>
DEMO</langsyntaxhighlight>
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE Sequence;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,ReadChar;
Line 1,529 ⟶ 1,915:
END;
ReadChar
END Sequence.</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
All native integers in Nanoquery can become arbitrarily large by default, so this program would run until it ran out of memory.
<langsyntaxhighlight Nanoquerylang="nanoquery">i = 1
while true
println i
i += 1
end</langsyntaxhighlight>
 
=={{header|Necromantus}}==
In Necromantus integer size is limited by the java's int.
<syntaxhighlight lang="necromantus">
<lang Necromantus>
let i = 0;
while true
Line 1,548 ⟶ 1,934:
i = i + 1;
}
</syntaxhighlight>
</lang>
 
=={{header|NetRexx}}==
===Rexx Built In===
NetRexx provides built-in support for very large precision arithmetic via the <tt>Rexx</tt> class.
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
 
Line 1,563 ⟶ 1,949:
say k_
end k_
</syntaxhighlight>
</lang>
 
===Using BigInteger===
Java's <tt>BigInteger</tt> class is also available for very large precision arithmetic.
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
 
Line 1,582 ⟶ 1,968:
say k_.toString(int radix)
end
</syntaxhighlight>
</lang>
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">(while (println (++ i)))</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">var i:int64 = 0
while true:
inc i
echo i</langsyntaxhighlight>
 
Using BigInts:
<langsyntaxhighlight lang="nim">import bigints
 
var i = 0.initBigInt
while true:
i += 1
echo i</langsyntaxhighlight>
 
=={{header|Oberon-2}}==
Works with oo2c Version 2
<langsyntaxhighlight lang="oberon2">
MODULE IntegerSeq;
IMPORT
Line 1,631 ⟶ 2,017:
 
END IntegerSeq.
</syntaxhighlight>
</lang>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
bundle Default {
class Count {
Line 1,646 ⟶ 2,032:
}
}
</syntaxhighlight>
</lang>
 
=={{header|OCaml}}==
with an imperative style:
<langsyntaxhighlight lang="ocaml">let () =
let i = ref 0 in
while true do
Line 1,656 ⟶ 2,042:
print_newline ();
incr i;
done</langsyntaxhighlight>
 
with a functional style:
<langsyntaxhighlight lang="ocaml">let () =
let rec aux i =
print_int i;
Line 1,665 ⟶ 2,051:
aux (succ i)
in
aux 0</langsyntaxhighlight>
 
=={{header|Oforth}}==
Line 1,673 ⟶ 2,059:
The loop will stop when out of memory
 
<langsyntaxhighlight Oforthlang="oforth">: integers 1 while( true ) [ dup . 1+ ] ;</langsyntaxhighlight>
 
=={{header|Ol}}==
Ol does not limit the size of numbers. So maximal number depends only on available system memory.
<langsyntaxhighlight lang="scheme">
(let loop ((n 1))
(print n)
(loop (+ 1 n)))
</syntaxhighlight>
</lang>
 
Sample sequence with break for large numbers:
<langsyntaxhighlight lang="scheme">
(let loop ((n 2))
(print n)
(unless (> n 100000000000000000000000000000000)
(loop (* n n))))
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,705 ⟶ 2,091:
OpenEdge has three data types that can be used for this task:
<ol><li>INTEGER (32-bit signed integer)
<langsyntaxhighlight lang="progress">DEF VAR ii AS INTEGER FORMAT "->>>>>>>>9" NO-UNDO.
 
DO WHILE TRUE:
ii = ii + 1.
DISPLAY ii.
END.</langsyntaxhighlight>
When an integer rolls over its maximum of 2147483647 error 15747 is raised (Value # too large to fit in INTEGER.).
</li>
<li>INT64 (64-bit signed integer)
<langsyntaxhighlight lang="progress">DEF VAR ii AS INT64 FORMAT "->>>>>>>>>>>>>>>>>>9" NO-UNDO.
 
DO WHILE TRUE:
ii = ii + 1.
DISPLAY ii.
END.</langsyntaxhighlight>
When a 64-bit integer overflows no error is raised and the signed integer becomes negative.
</li>
<li>DECIMAL (50 digits)
<langsyntaxhighlight lang="progress">DEF VAR de AS DECIMAL FORMAT "->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>9" NO-UNDO.
 
DO WHILE TRUE:
de = de + 1.
DISPLAY de.
END.</langsyntaxhighlight>
When a decimal requires mores than 50 digits error 536 is raised (Decimal number is too large.).
</li>
Line 1,735 ⟶ 2,121:
=={{header|Order}}==
Order supports arbitrarily-large positive integers natively. However, the simple version:
<langsyntaxhighlight lang="c">#include <order/interpreter.h>
 
#define ORDER_PP_DEF_8printloop ORDER_PP_FN( \
Line 1,742 ⟶ 2,128:
8printloop(8inc(8N)))) )
 
ORDER_PP( 8printloop(1) )</langsyntaxhighlight>
... while technically fulfilling the task, will probably never display anything, as most C Preprocessor implementations won't print their output until the file is done processing. Since the C Preprocessor is not technically Turing-complete, the Order interpreter has a maximum number of steps it can execute - but this number is very, very large (from the documentation: "the Order interpreter could easily be extended with a couple of hundred macros to prolong the wait well beyond the estimated lifetime of the sun"), so the compiler is rather more likely to simply run out of memory.
 
To actually see anything with GCC, add a maximum limit so that the task can complete:
<langsyntaxhighlight lang="c">#include <order/interpreter.h>
 
#define ORDER_PP_DEF_8printloop ORDER_PP_FN( \
Line 1,753 ⟶ 2,139:
8when(8less(8N, 99), 8printloop(8inc(8N))))) )
 
ORDER_PP( 8printloop(1) ) // 1, ..., 99,</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">n=0; while(1,print(++n))</langsyntaxhighlight>
 
=={{header|Pascal}}==
Line 1,762 ⟶ 2,148:
{{works with|Free_Pascal}}
Quad word has the largest positive range of all ordinal types
<langsyntaxhighlight lang="pascal">Program IntegerSequenceLimited;
var
Number: QWord = 0; // 8 bytes, unsigned: 0 .. 18446744073709551615
Line 1,770 ⟶ 2,156:
inc(Number);
until false;
end.</langsyntaxhighlight>
{{libheader|GMP}}
With the gmp library your patience is probably the limit :-)
<langsyntaxhighlight lang="pascal">Program IntegerSequenceUnlimited;
 
uses
Line 1,787 ⟶ 2,173:
mpz_add_ui(Number, Number, 1); //* increase Number *//
until false;
end.</langsyntaxhighlight>
 
=={{header|PascalABC.NET}}==
Uses functionality from [[Fibonacci n-step number sequences#PascalABC.NET]]
<syntaxhighlight lang="pascal">
// Integer sequence. Nigel Galloway: September 8th., 2022
function initInfinite(start: integer):=unfold(n->(n,n+1),start);
function initInfinite(start: biginteger):=unfold(n->(n,n+1),start);
begin
initInfinite(23).Take(10).Println;
initInfinite(-3).Take(10).Println;
initInfinite(2bi**70).Take(10).Println;
end.
</syntaxhighlight>
{{out}}
<pre>
23 24 25 26 27 28 29 30 31 32
-3 -2 -1 0 1 2 3 4 5 6
1180591620717411303424 1180591620717411303425 1180591620717411303426 1180591620717411303427 1180591620717411303428 1180591620717411303429 1180591620717411303430 1180591620717411303431 1180591620717411303432 1180591620717411303433
</pre>
 
Example 2.
 
<syntaxhighlight lang="pascal">
## 1.Step.Print
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
</pre>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">my $i = 0;
print ++$i, "\n" while 1;</langsyntaxhighlight>
 
On 64-bit Perls this will get to <tt>2^64-1</tt> then print <tt>1.84467440737096e+19</tt> forever. On 32-bit Perls using standard doubles this will get to <tt>999999999999999</tt> then start incrementing and printing floats until they lose precision. This behavior can be changed by adding something like:
<langsyntaxhighlight lang="perl">use bigint;
my $i = 0; print ++$i, "\n" while 1;</langsyntaxhighlight>
which makes almost all integers large (ranges are excluded). Faster alternatives exist with non-core modules, e.g.
* <tt>use bigint lib=>"GMP";</tt>
Line 1,803 ⟶ 2,218:
=={{header|Phix}}==
This will crash at 1,073,741,824 on 32 bit, or 4,611,686,018,427,387,904 on 64-bit, and as indicated best not to try this or any below under pwa/p2js:
<!--<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 1,810 ⟶ 2,225:
<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>-->
This will stall at 9,007,199,254,740,992 on 32-bit, and about twice the above on 64-bit.
(after ~15 or 19 digits of precision, adding 1 will simply cease to have any effect)
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #008080;">without</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
Line 1,820 ⟶ 2,235:
<span style="color: #000000;">a</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>-->
{{libheader|Phix/mpfr}}
This will probably carry on until the number has over 300 million digits (32-bit, you can
square that on 64-bit) which would probably take zillions of times longer than the
universe has already existed, if your hardware/OS/power grid kept going that long.
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #008080;">without</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 1,833 ⟶ 2,248:
<span style="color: #7060A8;">mpfr_printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%Zd\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">b</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</langsyntaxhighlight>-->
Lastly, a gui version you can run online [http://phix.x10.mx/p2js/Integers.htm here].
{{libheader|Phix/pGUI}}
{{libheader|Phix/online}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 1,860 ⟶ 2,275:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</langsyntaxhighlight>-->
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(for (I 1 T (inc I))
(printsp I) )</langsyntaxhighlight>
 
=={{header|Piet}}==
Line 1,902 ⟶ 2,317:
 
=={{header|Pike}}==
<langsyntaxhighlight Pikelang="pike">int i=1;
while(true)
write("%d\n", i++);</langsyntaxhighlight>
 
=={{header|PILOT}}==
<langsyntaxhighlight lang="pilot">C :n = 1
*InfiniteLoop
T :#n
C :n = n + 1
J :*InfiniteLoop</langsyntaxhighlight>
 
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
infinity: procedure options (main);
declare k fixed decimal (30);
Line 1,920 ⟶ 2,335:
((k do k = 1 to 999999999999999999999999999998))(f(31));
end infinity;
</syntaxhighlight>
</lang>
 
=={{header|PL/M}}==
Line 1,928 ⟶ 2,343:
will print numbers until the <code>ADDRESS</code> variable overflows.
 
<langsyntaxhighlight lang="plm">100H:
 
/* CP/M CALL AND NUMBER OUTPUT ROUTINE */
Line 1,961 ⟶ 2,376:
 
CALL BDOS(0,0);
EOF</langsyntaxhighlight>
 
To get around this limitation, the following program stores the number as an array of digits.
Line 1,967 ⟶ 2,382:
On a 64K CP/M system it will keep going until it has over 50.000 digits.
 
<langsyntaxhighlight lang="plm">100H:
 
/* CP/M CALL */
Line 2,030 ⟶ 2,445:
END;
 
EOF</langsyntaxhighlight>
 
 
=={{header|Plain English}}==
Numbers are signed 32-bit values, so this will overflow somewhere in the neighborhood of 2.1 billion.
<langsyntaxhighlight lang="plainenglish">To run:
Start up.
Put 1 into a number.
Line 2,043 ⟶ 2,458:
Bump the number.
Repeat.
Shut down.</langsyntaxhighlight>
 
=={{header|PostScript}}==
{{libheader|initlib}}
<langsyntaxhighlight lang="postscript">
1 {succ dup =} loop
</syntaxhighlight>
</lang>
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">try
<lang Powershell>try
{
for ([int]$i = 0;;$i++)
Line 2,059 ⟶ 2,474:
}
}
catch {break}</langsyntaxhighlight>
 
=={{header|Prolog}}==
<langsyntaxhighlight Prologlang="prolog">loop(I) :-
writeln(I),
I1 is I+1,
loop(I1).
</syntaxhighlight>
</lang>
 
===Constraint Handling Rules===
Works with SWI-Prolog and library '''CHR''' written by '''Tom Schrijvers''' and '''Jan Wielemaker'''
<langsyntaxhighlight Prologlang="prolog">:- use_module(library(chr)).
 
:- chr_constraint loop/1.
 
loop(N) <=> writeln(N), N1 is N+1, loop(N1).
</syntaxhighlight>
</lang>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">OpenConsole()
Repeat
a.q+1
PrintN(Str(a))
ForEver</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">i=1
while i:
print(i)
i += 1</langsyntaxhighlight>
 
Or, alternatively:
<langsyntaxhighlight lang="python">from itertools import count
 
for i in count():
print(i)</langsyntaxhighlight>
 
Pythons integers are of arbitrary large precision and so programs would probably keep going until OS or hardware system failure.
 
 
=={{header|QB64}}==
<syntaxhighlight lang="qb64">
 
Const iMax = 32767, UiMax = 65535
Const lMax = 2147483647, UlMax = 4294967295
Const iQBMax = 9223372036854775807, UiQBMax = 1844674407309551615
 
 
Dim iNum As _Integer64, iCount As _Integer64
Dim sChoice As String, sUnsigned As String, sQuit As String
Do While sChoice <> "I" And sChoice <> "L" And sChoice <> "6"
Input "Please choice among (I)nteger, (L)ong and Integer(6)4 ", sChoice
sChoice = UCase$(sChoice)
Loop
Do While sUnsigned <> "u" And sUnsigned <> "n"
Input "Please choice (U)nsigned or (N)ormal? ", sUnsigned
sUnsigned = LCase$(sUnsigned)
Loop
 
If sChoice = "I" Then
If sUnsigned = "n" Then iNum = iMax Else iNum = UiMax
ElseIf sChoice = "L" Then
If sUnsigned = "n" Then iNum = lMax Else iNum = UlMax
ElseIf sChoice = "6" Then
If sUnsigned = "n" Then iNum = iQBMax Else iNum = UiQBMax
End If
 
 
For iCount = 0 To iNum Step 1
Print iCount; " Press spacebar to exit "
sQuit = InKey$
Next
End
</syntaxhighlight>
 
=={{header|Q}}==
Line 2,102 ⟶ 2,553:
 
Using converge (the <tt>\</tt> adverb):
<langsyntaxhighlight lang="q">({-1 string x; x+1}\) 1</langsyntaxhighlight>
 
Using <tt>while</tt>:
<langsyntaxhighlight lang="q">i:0; while[1;-1 string (i+:1)]</langsyntaxhighlight>
 
=={{header|Quackery}}==
Quackery uses bignums.
 
<langsyntaxhighlight Quackerylang="quackery">0 [ 1+ dup echo cr again ]</langsyntaxhighlight>
 
=={{header|R}}==
<langsyntaxhighlight lang="r">z <- 0
repeat {
print(z)
z <- z + 1
}</langsyntaxhighlight>
 
=={{header|Racket}}==
Line 2,123 ⟶ 2,574:
Racket uses bignums, so counting should continue up to very large numbers. Naturally, printing these numbers will consume quite a bit of power.
 
<langsyntaxhighlight Racketlang="racket">#lang racket
(for ([i (in-naturals)]) (displayln i))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>.say for 1..*</langsyntaxhighlight>
 
=={{header|Rapira}}==
<syntaxhighlight lang="rapira">i := 1
while i do
output: i
i := i + 1
od</syntaxhighlight>
 
=={{header|Raven}}==
Raven uses signed 32 bit integer values.
<langsyntaxhighlight Ravenlang="raven">1 as $i
repeat TRUE while
$i "%d\n" print $i 1000 + as $i</langsyntaxhighlight>
 
=={{header|Red}}==
<langsyntaxhighlight lang="rebol">Red ["Integer sequence"]
 
i: 1
Line 2,144 ⟶ 2,602:
print i
i: i + 1
]</langsyntaxhighlight>
 
=={{header|Retro}}==
Retro uses signed integer values.
 
<langsyntaxhighlight Retrolang="retro">#0 [ [ n:put spa ] sip n:inc dup n:-zero? ] while drop</langsyntaxhighlight>
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*count all the protons, electrons, & whatnot in the universe, and then */
/*keep counting. According to some pundits in-the-know, one version of */
/*the big-bang theory is that the universe will collapse back to where */
Line 2,199 ⟶ 2,657:
 
/*It only took Deep Thought 7.5 million years to come up with the */
/*answer to everything (and it double-checked the answer). It was 42.*/</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
size = 10
 
Line 2,220 ⟶ 2,678:
n = n + 1
end
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
{| class="wikitable"
! RPL code
! Comment
|-
|
64 STWS
#1 '''DO'''
DUP 1 DISP
1 +
'''UNTIL''' #0 == '''END''' CLLCD
≫ ''''COUNT'''' STO
|
'''COUNT''' ''( -- )''
set integer size to 64 bits
Initialize counter and loop
display counter at top of screen
increment
Exit when 2^64-1 has been displayed
|}
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">1.step{|n| puts n}</langsyntaxhighlight>
 
The step method of Numeric takes two optional arguments. The limit defaults to infinity, the step size to 1.
Line 2,230 ⟶ 2,711:
Ruby 2.6 introduced open-ended ranges:
 
<langsyntaxhighlight lang="ruby">(1..).each{|n| puts n}</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">while 1
i = i + 1
print i
wend</langsyntaxhighlight>
Eventually as it gets larger it becomes a floating point.
 
=={{header|Rust}}==
{{works with|Rust 1.2}}
<langsyntaxhighlight lang="rust">fn main() {
for i in 0.. {
println!("{}", i);
}
}</langsyntaxhighlight>
 
 
Looping endlessly:
<langsyntaxhighlight lang="rust">extern crate num;
 
use num::bigint::BigUint;
Line 2,260 ⟶ 2,741:
i = i + BigUint::one();
}
}</langsyntaxhighlight>
 
=={{header|Salmon}}==
Line 2,266 ⟶ 2,747:
Salmon has built-in unlimited-precision integer arithmetic, so these examples will all continue printing decimal 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> digits).
 
<langsyntaxhighlight Salmonlang="salmon">iterate (i; [0...+oo])
i!;</langsyntaxhighlight>
 
or
 
<langsyntaxhighlight Salmonlang="salmon">for (i; 0; true)
i!;</langsyntaxhighlight>
 
or
 
<langsyntaxhighlight Salmonlang="salmon">variable i := 0;
while (true)
{
i!;
++i;
};</langsyntaxhighlight>
 
=={{header|Scala}}==
<syntaxhighlight lang ="scala">Stream from 1 foreach println</langsyntaxhighlight>
 
=={{header|Scheme}}==
 
<langsyntaxhighlight lang="scheme">
(let loop ((i 1))
(display i) (newline)
(loop (+ 1 i)))
</syntaxhighlight>
</lang>
 
Scheme does not limit the size of numbers.
 
=={{header|sed}}==
This program expects one line (consisting of a non-negative decimal integer) as start value:
<syntaxhighlight lang="sed">:l
p
s/^9*$/0&/
h
y/0123456789/1234567890/
x
G
s/.9*\n.*\([^0]\)/\1/
bl</syntaxhighlight>
{{out}}
<pre>
$ echo 1 | sed -f count_dec.sed | head
1
2
3
4
5
6
7
8
9
10
</pre>
 
=={{header|Seed7}}==
Limit 2147483647:
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 2,308 ⟶ 2,815:
writeln(number);
until number = 2147483647;
end func;</langsyntaxhighlight>
"Forever":
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "bigint.s7i";
 
Line 2,321 ⟶ 2,828:
incr(number);
until FALSE;
end func;</langsyntaxhighlight>
 
=={{header|Sidef}}==
No limit:
<syntaxhighlight lang="ruby">1..Inf -> each {.say}</syntaxhighlight>
<lang ruby>{|i| say i } * Math.inf;</lang>
 
=={{header|Smalltalk}}==
<langsyntaxhighlight lang="smalltalk">i := 0.
[
Stdout print:i; cr.
i := i + 1
] loop</langsyntaxhighlight>
will run forever.
 
=={{header|SSEM}}==
Since we have no Add instruction, we subtract -1 on each iteration instead of adding 1. The same -1 also serves as a jump target, taking advantage of a quirk of the SSEM architecture (the Current Instruction counter is incremented after the instruction has been executed, not before—so <tt>GOTO address</tt> has to be coded as <tt>GOTO address - 1</tt>).
<langsyntaxhighlight lang="ssem">01000000000000010000000000000000 0. Sub. 2 acc -= -1
01000000000000000000000000000000 1. 2 to CI goto -1 + 1
11111111111111111111111111111111 2. -1</langsyntaxhighlight>
 
=={{header|Standard ML}}==
Line 2,347 ⟶ 2,854:
IntInf.int (arbitrary precision).
 
<langsyntaxhighlight lang="sml">let
fun printInts(n) =
(
Line 2,355 ⟶ 2,862:
in
printInts(1)
end;</langsyntaxhighlight>
 
{{out}}
Line 2,371 ⟶ 2,878:
=={{header|SuperCollider}}==
The SuperCollider language has a 32-bit signed int, and a 64 bit signed float. Instead of locking the interpreter with an infinite loop, we post the values over time.
<syntaxhighlight lang="supercollider">
<lang SuperCollider>
i = Routine { inf.do { |i| i.yield } }; // return all integers, represented by a 64 bit signed float.
fork { inf.do { i.next.postln; 0.01.wait } }; // this prints them incrementally
</syntaxhighlight>
</lang>
 
A shorter form of the first line above, using list comprehensions:
<syntaxhighlight lang="supercollider">
<lang SuperCollider>
i = {:i, i<-(0..) };
</syntaxhighlight>
</lang>
 
=={{header|Swift}}==
<langsyntaxhighlight Swiftlang="swift">var i = 0
while true {
println(i++)
}</langsyntaxhighlight>
 
=={{header|Symsyn}}==
<syntaxhighlight lang="symsyn">
<lang Symsyn>
| The following code will run forever
| Symsyn uses a 64 bit signed integer
Line 2,398 ⟶ 2,905:
+ x
go lp
</syntaxhighlight>
</lang>
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
while true {puts [incr i]}</langsyntaxhighlight>
 
=={{header|TI SR-56}}==
{| class="wikitable"
|+ Texas Instruments SR-56 Program Listing for "Integer sequence"
|-
! Display !! Key !! Display !! Key !! Display !! Key !! Display !! Key
|-
| 00 84 || + || 25 || || 50 || || 75 ||
|-
| 01 01 || 1 || 26 || || 51 || || 76 ||
|-
| 02 94 || = || 27 || || 52 || || 77 ||
|-
| 03 59 || *pause || 28 || || 53 || || 78 ||
|-
| 04 42 || RST || 29 || || 54 || || 79 ||
|-
| 05 || || 30 || || 55 || || 80 ||
|-
| 06 || || 31 || || 56 || || 81 ||
|-
| 07 || || 32 || || 57 || || 82 ||
|-
| 08 || || 33 || || 58 || || 83 ||
|-
| 09 || || 34 || || 59 || || 84 ||
|-
| 10 || || 35 || || 60 || || 85 ||
|-
| 11 || || 36 || || 61 || || 86 ||
|-
| 12 || || 37 || || 62 || || 87 ||
|-
| 13 || || 38 || || 63 || || 88 ||
|-
| 14 || || 39 || || 64 || || 89 ||
|-
| 15 || || 40 || || 65 || || 90 ||
|-
| 16 || || 41 || || 66 || || 91 ||
|-
| 17 || || 42 || || 67 || || 92 ||
|-
| 18 || || 43 || || 68 || || 93 ||
|-
| 19 || || 44 || || 69 || || 94 ||
|-
| 20 || || 45 || || 70 || || 95 ||
|-
| 21 || || 46 || || 71 || || 96 ||
|-
| 22 || || 47 || || 72 || || 97 ||
|-
| 23 || || 48 || || 73 || || 98 ||
|-
| 24 || || 49 || || 74 || || 99 ||
|}
 
Asterisk denotes 2nd function key.
 
{| class="wikitable"
|+ Register allocation
|-
| 0: Unused || 1: Unused || 2: Unused || 3: Unused || 4: Unused
|-
| 5: Unused || 6: Unused || 7: Unused || 8: Unused || 9: Unused
|}
 
Annotated listing:
<syntaxhighlight lang="text">
+ 1 = // Increment the number
*pause // Flash the number on the display
RST // Loop
</syntaxhighlight>
 
'''Usage:'''
 
Press CLR RST R/S. Incrementing numbers will flash on the screen. In one minute, the program counts to 86. Most of this time is taken displaying the number on the screen.
 
'''Note:'''
 
The minimum possible "Integer Sequence" program, which increments the number without displaying it, is:
 
<syntaxhighlight lang="text">
+ 1 // Increment the number
RST // Loop
</syntaxhighlight>
 
This program runs much faster. In one minute, the program counts to 640.
 
=={{header|Tiny BASIC}}==
<langsyntaxhighlight lang="tinybasic">
REM will overflow after 32767
LET N = 0
Line 2,411 ⟶ 3,007:
LET N = N + 1
GOTO 10
</syntaxhighlight>
</lang>
 
 
=={{header|True BASIC}}==
<langsyntaxhighlight lang="qbasic">LET i = 0
 
DO
Line 2,422 ⟶ 3,018:
LOOP
 
END</langsyntaxhighlight>
 
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
LOOP n=0,999999999
n=n+1
ENDLOOP</langsyntaxhighlight>
=={{header|Uiua}}==
<syntaxhighlight lang="Uiua">
⍢(&p.+1)1 1
</syntaxhighlight>
{{out}}
<pre>
Previous output truncated...
318259
318260
318261
318262
318263
318264
318265
318266
318267
318268
318269
318270
318271
318272
318273
318274
318275
318276
318277
318278
318279
318280
318281
318282
318283
318284
318285
318286
318287
318288
318289
318290
318291
318292
318293
318294
318295
318296
318297
318298
318299
318300
318301
318302
318303
318304
318305
318306
318307
318308
318309
318310
318311
318312
318313
318314
318315
 
 
You can increase the execution time limit in the editor settings
 
</pre>
=={{header|UNIX Shell}}==
 
<langsyntaxhighlight lang="sh">#!/bin/sh
num=0
while true; do
echo $num
num=`expr $num + 1`
done</langsyntaxhighlight>
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa">#
# integer sequence
#
Line 2,451 ⟶ 3,115:
out i endl console
inc i
end while</langsyntaxhighlight>
 
=={{header|Ursalang}}==
<syntaxhighlight lang="ursalang">
let i = 1
loop {
print(i)
i := i + 1
}
</syntaxhighlight>
 
=={{header|Vala}}==
<langsyntaxhighlight lang="vala">
uint i = 0;
while (++i < uint.MAX)
stdout.printf("%u\n", i);
</syntaxhighlight>
</lang>
 
 
=={{header|Verilog}}==
<langsyntaxhighlight Veriloglang="verilog">module main;
integer i;
 
Line 2,474 ⟶ 3,147:
$finish ;
end
endmodule</langsyntaxhighlight>
 
=={{header|Visual Basic .NET}}==
Line 2,483 ⟶ 3,156:
Note that attempting to store any value larger than the maximum value of any given type (say 2 147 483 648 for an Integer) will result in an OverflowException being thrown (<i>"Arithmetic operation resulted in an overflow."</i>)
 
<langsyntaxhighlight lang="vbnet"> For i As Integer = 0 To Integer.MaxValue
Console.WriteLine(i)
Next</langsyntaxhighlight>
 
===Arbitrarily large numbers===
One could use the '''System.Numerics''' library as the C# example did, or one can do the following.<br/>A list of Long Integers is maintained as the incremented number. As the incremented value approaches the maximum allowed (''base'') in the first element of ''ar'', a new item is inserted at the beginning of the list to extend the incremented number. The process has the limitation of when the ''ar'' array is enlarged to the point where the program exhausts the available memory, it ought to indicate failure and terminate. It is my understanding that a '''List''' count is backed by an '''Integer.MaxValue''' limitation and there may also be a 2 GB per object limitation involved. Since writing to the Console is such a slow process, I lack the patience to wait for the program (as written) to fail. If the program is tweaked to fail early, the practical limit seems to be a number 2,415,919,086 digits in length.
<langsyntaxhighlight lang="vbnet">Imports System.Console
 
Module Module1
Line 2,533 ⟶ 3,206:
TimeStamp("keypress")
End Sub
End Module</langsyntaxhighlight>
{{out}}
<pre>1
Line 2,545 ⟶ 3,218:
 
=={{header|WDTE}}==
<langsyntaxhighlight WDTElang="wdte">let s => import 'stream';
 
s.new 0 (+ 1)
-> s.map (io.writeln io.stdout)
-> s.drain
;</langsyntaxhighlight>
 
WDTE's number type is, at the time of writing, backed by Go's <code>float64</code> type, so all of the same limitations that apply there apply here. Also, this should '''not''' be run in the WDTE playground, as it will run with no output until the browser crashes or is killed.
Line 2,560 ⟶ 3,233:
 
Also, the ''System.print'' method in the standard library will only display a maximum of 14 digits before switching to scientific notation. To get around this one can use instead the ''Fmt.print'' method of the ''Wren-fmt'' module which displays integers 'normally' up to the maximum and also caters for BigInts as well.
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Fmt
import "./big" for BigInt
 
Line 2,570 ⟶ 3,243:
Fmt.print("$i", bi)
bi = bi + 1
}</langsyntaxhighlight>
 
=={{header|XBasic}}==
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "integseq"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
 
DO WHILE $$TRUE
INC i
PRINT i
LOOP
 
END FUNCTION
END PROGRAM</syntaxhighlight>
 
=={{header|XLISP}}==
<langsyntaxhighlight lang="lisp">(defun integer-sequence-from (x)
(print x)
(integer-sequence-from (+ x 1)) )
 
(integer-sequence-from 1)</langsyntaxhighlight>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">\Displays integers up to 2^31-1 = 2,147,483,647
code CrLf=9, IntOut=11;
int N;
Line 2,587 ⟶ 3,277:
N:= N+1;
until N<0;
]</langsyntaxhighlight>
 
 
=={{header|Yabasic}}==
<langsyntaxhighlight lang="yabasic">i = 1
 
repeat
Line 2,597 ⟶ 3,287:
i = i + 1
until i = 0
end</langsyntaxhighlight>
 
 
Line 2,603 ⟶ 3,293:
===16-Bit===
The Amstrad CPC's screen isn't big enough to show it all at once, but here you go. This prints numbers out (in hexadecimal) from <tt>0x0001</tt> to <tt>0xFFFF</tt>.
<langsyntaxhighlight lang="z80">org &1000
PrintChar equ &BB5A
ld hl,1 ;START AT ONE
Line 2,650 ⟶ 3,340:
adc a,&40
jp PrintChar
;ret</langsyntaxhighlight>
 
===Arbitrarily Large Integers===
This version displays an ever-increasing 64-bit unsigned integer. Unlike the previous version, this one continues forever and underflows to 0 after it reaches <tt>0xFFFFFFFFFFFFFFFF</tt>. This logic can be extended to integers of up to 128 bytes in size (since <code>IX+#</code> uses a signed offset, you'd need some way to alter the pointer to memory if you wanted even larger numbers than that, it's possible but a bit cumbersome. Not that this method wasn't cumbersome to begin with.)
<langsyntaxhighlight lang="z80">org &1000
PrintChar equ &BB5A
ld ix,NumberRam
Line 2,741 ⟶ 3,431:
 
NumberRam: ;a 64-bit value, stored little-endian
db 01,00,00,00,00,00,00,00</langsyntaxhighlight>
 
=={{header|Zig}}==
<syntaxhighlight lang="zig">
const stdout = @import("std").io.getStdOut().writer();
 
pub fn main() !void {
var i: u128 = 1;
 
while (true) : (i += 1) {
try stdout.print("{}, ", .{i});
}
}
</syntaxhighlight>
{{out}}
<pre>
...
324136, 324137, 324138, 324139, 324140, 324141, 324142, 324143, 324144, 324145, 324146, 324147, 324148, 324149, 324150, 324151, 324152, 324153, 324154, 324155, 324156, 324157, 324158, 324159, 324160, 324161, 324162, 324163, 324164, 324165, 324166, 324167, 324168, 324169, 324170, 324171, 324172, 324173, 324174, 324175, 324176, 324177, 324178, 324179, 324180, 324181, 324182, 324183, 324184, 324185, 324186, 324187, 324188, 324189, 324190, 324191,
</pre>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">[1..].pump(Console.println) // eager
m:=(1).MAX; [1..m].pump(Console.println) // (1).MAX is 9223372036854775807
[1..].pump(100,Console.println) // lazy</langsyntaxhighlight>
 
 
22

edits