Integer sequence: Difference between revisions
→{{header|Zig}}
m (→{{header|Joy}}) |
|||
(39 intermediate revisions by 20 users not shown) | |||
Line 11:
=={{header|0815}}==
<
=={{header|11l}}==
<
print(i)</
=={{header|360 Assembly}}==
For maximum compatibility, this program uses only the basic instruction set (S/360).
<
INTSEQED CSECT
USING INTSEQED,12
Line 33:
DW DS 0D,PL8 pack dec 15num
EM12 DC X'402020202020202020202120' mask CL12 11num
END INTSEQED</
{{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.
<
MVI A, 0 ; move immediate
LOOP: INR A ; increment
Line 58 ⟶ 72:
JMP LOOP ; jump unconditionally
END</
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.)
<
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</
=={{header|Action!}}==
<
CARD i
Line 108 ⟶ 122:
UNTIL i=0
OD
RETURN</
{{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}}==
<
procedure Integers is
Value : Integer := 1;
Line 124 ⟶ 138:
Value := Value + 1; -- raises exception Constraint_Error on overflow
end loop;
end Integers;</
Alternative (iterating through all values of Positive (positive part of Integer) without endless loop):
<
procedure Positives is
begin
Line 132 ⟶ 146:
Ada.Text_IO.Put_Line (Positive'Image (Value));
end loop;
end Positives;</
=={{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]].
<
(
FOR i DO
printf(($g(0)","$,i))
OD
)</
Partial output:
<pre>
Line 151 ⟶ 165:
=={{header|ALGOL W}}==
<
% 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.</
=={{header|Applesoft BASIC}}==
Integer variables can be within the range of -32767 to 32767.
<
20 PRINT I%;
30 I% = I% + 1
40 PRINT ", ";
50 GOTO 20</
Last screen of scrolled output:
<
51, 32652, 32653, 32654, 32655, 32656, 3
2657, 32658, 32659, 32660, 32661, 32662,
Line 195 ⟶ 209:
, 32766, 32767
?ILLEGAL QUANTITY ERROR IN 30
]</
=={{header|ARM Assembly}}==
<
.global main
Line 212 ⟶ 226:
@ call to 'PRINT' routine
add r0, r0, #1 @ increment R0
b repeat @ unconditional branch</
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}}==
<
HEY CHRISTMAS TREE n
YOU SET US UP @NO PROBLEMO
Line 225 ⟶ 511:
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED</
=={{header|Arturo}}==
<
while ø [
print i
inc 'i
]</
=={{header|AutoHotkey}}==
This uses traytip to show the results. A msgbox, tooltip, or fileappend could also be used.
<syntaxhighlight lang="autohotkey">x=0
Loop
TrayTip, Count, % ++x</
=={{header|AWK}}==
<
for( i=0; i != i + 1; i++ )
print( i )
}</
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.
<
End
0→I
Line 257 ⟶ 543:
Disp I▶Dec,i
I++
EndIf I=0</
=={{header|BASIC}}==
{{works with|ZX Spectrum Basic}}
<
20 LET A = A + 1
30 PRINT A
40 GO TO 20</
{{works with|QBasic}}
<
DO: A = A + 1: PRINT A: LOOP 1</
=={{header|BASIC256}}==
<
do
print i
i += 1
until i = 0</
=={{header|Batch File}}==
Variables are limited to 32bit integer, capable of a maximum value of <code>2,147,483,647</code>
<
@echo off
set number=0
Line 287 ⟶ 573:
echo %number%
goto loop
</syntaxhighlight>
{{out}}
<pre>
Line 305 ⟶ 591:
{{works with|BBC BASIC for Windows}}
Native version, limited to 53-bit integers (maximum output 9007199254740992):
<
REPEAT
i += 1
PRINT TAB(0,0) i;
UNTIL FALSE</
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):
<
PROC_himeinit("")
reg% = 1
Line 319 ⟶ 605:
SYS `hi_Incr`, ^reg%, ^reg%
PRINT TAB(0,0) FN_higetdec(reg%);
UNTIL FALSE</
=={{header|bc}}==
<syntaxhighlight lang
=={{header|beeswax}}==
Using an ordinary loop structure:
<
_1>{d</
Using a jump instruction:
<syntaxhighlight lang
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.
<
=={{header|BQN}}==
While the input is lesser than or equal to infinity, print, then increment.
<
(1+•Show) _while_ (≤⟜∞) 1</
=={{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)</
=={{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.
<
-------------------[>>-<++++++++++<[+>-<]]>[-<+>]<++++++++++++++++++
++++++++++++++++++++++++++++++>]<[<]>>[-<+++++++++++++++++++++++++++
++++++++++++++++++++++>]>]>[>>>]<<<[.<<<]<.>>>+]</
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.
<
--------------------[>>-<++++++++++<[+>-<]]>[-<+>]<+++++++++++++++++
+++++++++++++++++++++++++++++++>]<[<]>>[-<++++++++++++++++++++++++++
+++++++++++++++++++++++>]>]>[>>>]<<<[.<<<]<.>>-]</
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.
<
=={{header|Brat}}==
<
loop {
p i
i = i + 1
}</
=={{header|Burlesque}}==
<
1R@
</syntaxhighlight>
=={{header|C}}==
Prints from 1 to max unsigned integer (usually 2**32 -1), then stops.
<
int main()
Line 392 ⟶ 678:
return 0;
}</
==={{libheader|GMP}}===
This one never stops. It's not even likely that you'll run out of memory before you run out of patience. <
int main()
Line 408 ⟶ 694:
return 0;
}</
==={{libheader|OpenSSL}}===
OpenSSL provides arbitrarily large integers.
<
#include <openssl/err.h> /* ERR_*() */
#include <stdio.h> /* fprintf(), puts() */
Line 441 ⟶ 727:
}
/* NOTREACHED */
}</
=={{header|C sharp|C#}}==
<
using System.Numerics;
Line 457 ⟶ 743:
}
}
}</
=={{header|C++}}==
<
#include <iostream>
#include <limits>
Line 470 ⟶ 756:
while (i < std::numeric_limits<decltype(i)>::max())
std::cout << ++i << '\n';
}</
<!--
<
#include <iostream>
Line 490 ⟶ 776:
// Do nothing
}
}</
-->
=={{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>
=={{header|Clean}}==
In Clean this example has a limit of basically 2147483648.
<
import StdEnv
Start = [x \\ x <- [1..]]</
Output:
Line 514 ⟶ 800:
=={{header|Clojure}}==
<
=={{header|CLU}}==
<
% 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 </
=={{header|COBOL}}==
<
PROGRAM-ID. Int-Sequence.
Line 552 ⟶ 838:
GOBACK
.</
=={{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.
<
# 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>
output
<syntaxhighlight lang="text">
> coffee foo.coffee | head -5
199999999999999999999999999999999999999999999999999999
Line 603 ⟶ 889:
200000000000000000000000000000000000000000000000000002
200000000000000000000000000000000000000000000000000003
</syntaxhighlight>
=={{header|Common Lisp}}==
<
If your compiler does tail call elimination (note: this has absolutely no advantage over normal loops):
<
(funcall (compile 'pp) 1) ; it's less likely interpreted mode will eliminate tails</
=={{header|Component Pascal}}==
BlackBox Component Builder
<
MODULE IntegerSequence;
IMPORT StdLog;
Line 630 ⟶ 916:
END IntegerSequence.
</syntaxhighlight>
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.
<
JMP start
one: 1</
=={{header|Cowgol}}==
Line 648 ⟶ 934:
This program will count up to 2^32-1, and then stop.
<
var n: uint32 := 1;
Line 655 ⟶ 941:
print_nl();
n := n + 1;
end loop;</
The following program will keep going until it runs out of memory, using one byte per digit.
<
sub print_back(s: [uint8]) is
Line 703 ⟶ 989:
infnum := incr(infnum);
print_back(infnum);
end loop;</
=={{header|Crystal}}==
Will run as long as enough memory to represent numbers.
<
(1.to_big_i ..).each { |i| puts i } </
=={{header|D}}==
<
void main() {
Line 718 ⟶ 1,004:
while (true)
writeln(++i);
}</
Alternative:
<
void integerSequence(T)() if (isIntegral!T || is(T == BigInt)) {
Line 755 ⟶ 1,041:
default: writeln("\nBye bye!"); break;
}
}</
=={{header|Dc}}==
<syntaxhighlight lang
=={{header|DCL}}==
<
$ loop:
$ write sys$output i
$ i = i + 1
$ goto loop</
{{out}}
<pre>1
Line 782 ⟶ 1,068:
=={{header|Delphi}}==
<
{$APPTYPE CONSOLE}
Line 791 ⟶ 1,077:
for i := 1 to High(i) do
WriteLn(i);
end.</
=={{header|DWScript}}==
High(i) returns the maximum supported value, typically, it is the highest signed 64 bit integer.
<
var i: Integer;
for i:=1 to High(i) do
PrintLn(i);
</syntaxhighlight>
=={{header|Dyalect}}==
<
while true {
n += 1
print(n)
}</
=={{header|Déjà Vu}}==
<
while /= -- dup dup:
Line 817 ⟶ 1,103:
++
drop</
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}}==
<
=={{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}}==
<
(lib 'bigint) ;; arbitrary length integers
(for ((n (in-naturals))) (writeln n))
</syntaxhighlight>
=={{header|EDSAC order code}}==
<
================
Line 855 ⟶ 1,157:
P0D [ constant: 1 ]
EZPF [ begin at load point ]</
=={{header|Eiffel}}==
<
class
APPLICATION
Line 881 ⟶ 1,183:
number:INTEGER_64
end
</syntaxhighlight>
=={{header|Elena}}==
ELENA 4.x :
<
public program()
Line 896 ⟶ 1,198:
i += 1u
}
}</
=={{header|Elixir}}==
<
=={{header|Emacs Lisp}}==
Displays in the message area interactively, or to standard output under <code>-batch</code>.
<
(message "%d" (1+ i)))</
=={{header|Erlang}}==
<
=={{header|ERRE}}==
<syntaxhighlight lang="text">
.............
A%=0
Line 920 ⟶ 1,222:
END LOOP
.............
</syntaxhighlight>
% 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}}==
<
i = 0
while 1 do
? i
i += 1
end while</
=={{header|F_Sharp|F#}}==
<
let rec integers i =
seq { yield i
yield! integers (i+1) }
Seq.iter (printfn "%d") (integers 1)</
lazy sequence of int32 starting from 0
<
lazy sequence of int32 starting from n
<
lazy sequence (not necessarily of int32) starting from n (using unfold anamorphism)
<
Seq.unfold (fun n -> Some (n, n + LanguagePrimitives.GenericOne)) n</
<div>
> numbers 0 |> Seq.take 10;;
Line 983 ⟶ 1,285:
=={{header|Factor}}==
<
1 lfrom [ . ] leach</
=={{header|Fantom}}==
<
class Main
{
Line 1,001 ⟶ 1,303:
}
}
</syntaxhighlight>
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}}==
<
while 1 do !n;!' '; n:=n+1 od</
=={{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:
<
^o" "<</
=={{header|Forth}}==
<
0 begin 1+ dup cr u. dup -1 = until drop ;</
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<
implicit none
Line 1,033 ⟶ 1,335:
n = n + 1
end do
end program</
=={{header|FreeBASIC}}==
<
' 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</
=={{header|Frink}}==
All of Frink's numbers can be arbitrarily-sized:
<syntaxhighlight lang="frink">
i=0
while true
Line 1,060 ⟶ 1,362:
i = i + 1
}
</syntaxhighlight>
=={{header|FunL}}==
The following has no limit since FunL has arbitrary size integers.
<
=={{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">
fun main(n: int): [n]int = iota n
</syntaxhighlight>
=={{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}}==
<
local n;
n := 1;
Line 1,087 ⟶ 1,410:
# Prepare some coffee
InfiniteLoop();</
=={{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.
<
import "fmt"
Line 1,099 ⟶ 1,422:
fmt.Println(i)
}
}</
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.
<
import (
Line 1,113 ⟶ 1,436:
fmt.Println(i)
}
}</
=={{header|Gridscript}}==
<
#INTEGER SEQUENCE.
Line 1,128 ⟶ 1,451:
(9,1):INCREMENT
(11,1):GOTO 0
</syntaxhighlight>
=={{header|Groovy}}==
<
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 }</
=={{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.
<
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]</
=={{header|GW-BASIC}}==
<
20 PRINT A#
30 A#=A#+1
40 GOTO 20</
=={{header|Haskell}}==
<syntaxhighlight lang
Or less imperatively:
<
=={{header|HolyC}}==
Prints from 1 to max unsigned 64 bit integer (2**64 -1), then stops.
<
while (++i) Print("%d\n", i);
</syntaxhighlight>
=={{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.
<
every write(seq(1)) # the most concise way
end</
=={{header|IS-BASIC}}==
<
110 PRINT I;
120 NEXT</
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.
<
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).
<
=={{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
public static void main(String[] args) {
for(long i = 1; ;i++) System.out.println(i);
}
}
</syntaxhighlight>
"Forever":
<syntaxhighlight lang="java">
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);
}
}
</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.
<
while (true)
document.write(++i + ' ');</
This example uses a BigInt[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt] literal to support arbitrary large integers.
<
while (true)
document.write(++i + ' ');</
=={{header|Joy}}==
<
1 [0 >] [dup put succ] while pop.</syntaxhighlight>
Line 1,229 ⟶ 1,596:
=={{header|jq}}==
Consider, for example:
<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}}==
<
while true
println(i += 1)
end</
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}}==
<
Using a <code>while</code> loop:
<
=={{header|Kotlin}}==
<
// version 1.0.5-2
Line 1,269 ⟶ 1,644:
n += BigInteger.ONE
}
}</
=={{header|Lambdatalk}}==
The long_add primitive allow counting beyond the javascript numbers limits, depending on the system memory.
<
{def infinite_set
{lambda {:i}
Line 1,283 ⟶ 1,658:
{infinite_set 0}
-> 0 1 2 3 ... forever
</syntaxhighlight>
=={{header|Lang}}==
<syntaxhighlight lang="lang">
# LONG limit (64 bits signed)
$l = 1L
loop {
fn.println($l)
$l += 1
}
</syntaxhighlight>
=={{header|Lang5}}==
<
=={{header|Lasso}}==
<
while(#number > 0) => {^
#number++
' '
//#number > 100 ? #number = -2 // uncomment this row if you want to halt the run after proving concept
^}</
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.
<
i=i+1
locate 1,1
Line 1,305 ⟶ 1,691:
scan
wend
</
=={{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:
<
include "sys.m"; sys: Sys;
Line 1,333 ⟶ 1,719:
}
}
</syntaxhighlight>
=={{header|Lingo}}==
<
repeat while i>0
put i
i = i+1
end repeat</
Lingo uses signed 32 bit integers, so max. supported integer value is 2147483647:
<
-- 2147483647</
Beyond this limit values behave like negative numbers:
<
-- -2147483648
put the maxInteger+2
-- -2147483647</
Up to the (quite high) number where floats (double-precission) start rounding, floats can be used to exceed the integer limit:
<
put float(the maxInteger)+1
Line 1,369 ⟶ 1,755:
-- 2
-- 3
-- ...</
=={{header|LLVM}}==
{{trans|C}}
<
; 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" }</
=={{header|Lua}}==
<
i = 1
Line 1,421 ⟶ 1,807:
i = i + 1
end
</syntaxhighlight>
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
\\ easy way
a=1@
Line 1,448 ⟶ 1,834:
\\ this flag reset to false before restart.
{loop : Print a : a++}
</syntaxhighlight>
=={{header|Maple}}==
Maple has arbitrary-precision integers so there are no built-in limits on the size of the integers represented.
<
print(n)
end do;</
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Built in arbitrary precision support means the following will not overflow.
<syntaxhighlight lang="mathematica">
x = 1;
Monitor[While[True, x++], x]
</syntaxhighlight>
=={{header|MATLAB}} / {{header|Octave}}==
<
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
<
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.
<
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}}==
<
=={{header|min}}==
{{works with|min|0.19.3}}
min's integers are 64-bit signed. This will eventually overflow.
<
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">1 П4 ИП4 С/П КИП4 БП 02</
=={{header|ML/I}}==
<
"" Integer sequence
"" Will overflow when it reaches implementation-defined signed integer limit
Line 1,511 ⟶ 1,897:
MCGO L1
>
DEMO</
=={{header|Modula-2}}==
<
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,ReadChar;
Line 1,529 ⟶ 1,915:
END;
ReadChar
END Sequence.</
=={{header|Nanoquery}}==
All native integers in Nanoquery can become arbitrarily large by default, so this program would run until it ran out of memory.
<
while true
println i
i += 1
end</
=={{header|Necromantus}}==
In Necromantus integer size is limited by the java's int.
<syntaxhighlight lang="necromantus">
let i = 0;
while true
Line 1,548 ⟶ 1,934:
i = i + 1;
}
</syntaxhighlight>
=={{header|NetRexx}}==
===Rexx Built In===
NetRexx provides built-in support for very large precision arithmetic via the <tt>Rexx</tt> class.
<
options replace format comments java crossref symbols binary
Line 1,563 ⟶ 1,949:
say k_
end k_
</syntaxhighlight>
===Using BigInteger===
Java's <tt>BigInteger</tt> class is also available for very large precision arithmetic.
<
options replace format comments java crossref symbols binary
Line 1,582 ⟶ 1,968:
say k_.toString(int radix)
end
</syntaxhighlight>
=={{header|NewLISP}}==
<
=={{header|Nim}}==
<
while true:
inc i
echo i</
Using BigInts:
<
var i = 0.initBigInt
while true:
i += 1
echo i</
=={{header|Oberon-2}}==
Works with oo2c Version 2
<
MODULE IntegerSeq;
IMPORT
Line 1,631 ⟶ 2,017:
END IntegerSeq.
</syntaxhighlight>
=={{header|Objeck}}==
<
bundle Default {
class Count {
Line 1,646 ⟶ 2,032:
}
}
</syntaxhighlight>
=={{header|OCaml}}==
with an imperative style:
<
let i = ref 0 in
while true do
Line 1,656 ⟶ 2,042:
print_newline ();
incr i;
done</
with a functional style:
<
let rec aux i =
print_int i;
Line 1,665 ⟶ 2,051:
aux (succ i)
in
aux 0</
=={{header|Oforth}}==
Line 1,673 ⟶ 2,059:
The loop will stop when out of memory
<
=={{header|Ol}}==
Ol does not limit the size of numbers. So maximal number depends only on available system memory.
<
(let loop ((n 1))
(print n)
(loop (+ 1 n)))
</syntaxhighlight>
Sample sequence with break for large numbers:
<
(let loop ((n 2))
(print n)
(unless (> n 100000000000000000000000000000000)
(loop (* n n))))
</syntaxhighlight>
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)
<
DO WHILE TRUE:
ii = ii + 1.
DISPLAY ii.
END.</
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)
<
DO WHILE TRUE:
ii = ii + 1.
DISPLAY ii.
END.</
When a 64-bit integer overflows no error is raised and the signed integer becomes negative.
</li>
<li>DECIMAL (50 digits)
<
DO WHILE TRUE:
de = de + 1.
DISPLAY de.
END.</
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:
<
#define ORDER_PP_DEF_8printloop ORDER_PP_FN( \
Line 1,742 ⟶ 2,128:
8printloop(8inc(8N)))) )
ORDER_PP( 8printloop(1) )</
... 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:
<
#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,</
=={{header|PARI/GP}}==
<
=={{header|Pascal}}==
Line 1,762 ⟶ 2,148:
{{works with|Free_Pascal}}
Quad word has the largest positive range of all ordinal types
<
var
Number: QWord = 0; // 8 bytes, unsigned: 0 .. 18446744073709551615
Line 1,770 ⟶ 2,156:
inc(Number);
until false;
end.</
{{libheader|GMP}}
With the gmp library your patience is probably the limit :-)
<
uses
Line 1,787 ⟶ 2,173:
mpz_add_ui(Number, Number, 1); //* increase Number *//
until false;
end.</
=={{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}}==
<
print ++$i, "\n" while 1;</
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:
<
my $i = 0; print ++$i, "\n" while 1;</
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:
<!--<
<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>
<!--</
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)
<!--<
<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>
<!--</
{{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.
<!--<
<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>
<!--</
Lastly, a gui version you can run online [http://phix.x10.mx/p2js/Integers.htm here].
{{libheader|Phix/pGUI}}
{{libheader|Phix/online}}
<!--<
<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>
<!--</
=={{header|PicoLisp}}==
<
(printsp I) )</
=={{header|Piet}}==
Line 1,902 ⟶ 2,317:
=={{header|Pike}}==
<
while(true)
write("%d\n", i++);</
=={{header|PILOT}}==
<
*InfiniteLoop
T :#n
C :n = n + 1
J :*InfiniteLoop</
=={{header|PL/I}}==
<syntaxhighlight 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>
=={{header|PL/M}}==
Line 1,928 ⟶ 2,343:
will print numbers until the <code>ADDRESS</code> variable overflows.
<
/* CP/M CALL AND NUMBER OUTPUT ROUTINE */
Line 1,961 ⟶ 2,376:
CALL BDOS(0,0);
EOF</
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.
<
/* CP/M CALL */
Line 2,030 ⟶ 2,445:
END;
EOF</
=={{header|Plain English}}==
Numbers are signed 32-bit values, so this will overflow somewhere in the neighborhood of 2.1 billion.
<
Start up.
Put 1 into a number.
Line 2,043 ⟶ 2,458:
Bump the number.
Repeat.
Shut down.</
=={{header|PostScript}}==
{{libheader|initlib}}
<
1 {succ dup =} loop
</syntaxhighlight>
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">try
{
for ([int]$i = 0;;$i++)
Line 2,059 ⟶ 2,474:
}
}
catch {break}</
=={{header|Prolog}}==
<
writeln(I),
I1 is I+1,
loop(I1).
</syntaxhighlight>
===Constraint Handling Rules===
Works with SWI-Prolog and library '''CHR''' written by '''Tom Schrijvers''' and '''Jan Wielemaker'''
<
:- chr_constraint loop/1.
loop(N) <=> writeln(N), N1 is N+1, loop(N1).
</syntaxhighlight>
=={{header|PureBasic}}==
<
Repeat
a.q+1
PrintN(Str(a))
ForEver</
=={{header|Python}}==
<
while i:
print(i)
i += 1</
Or, alternatively:
<
for i in count():
print(i)</
Pythons integers are of arbitrary large precision and so programs would probably keep going until OS or hardware system failure.
Line 2,100 ⟶ 2,515:
=={{header|QB64}}==
<syntaxhighlight lang="qb64">
Const iMax = 32767, UiMax = 65535
Line 2,132 ⟶ 2,547:
Next
End
</syntaxhighlight>
=={{header|Q}}==
Line 2,138 ⟶ 2,553:
Using converge (the <tt>\</tt> adverb):
<
Using <tt>while</tt>:
<
=={{header|Quackery}}==
Quackery uses bignums.
<
=={{header|R}}==
<
repeat {
print(z)
z <- z + 1
}</
=={{header|Racket}}==
Line 2,159 ⟶ 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.
<
(for ([i (in-naturals)]) (displayln i))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
=={{header|Rapira}}==
<
while i do
output: i
i := i + 1
od</
=={{header|Raven}}==
Raven uses signed 32 bit integer values.
<
repeat TRUE while
$i "%d\n" print $i 1000 + as $i</
=={{header|Red}}==
<
i: 1
Line 2,187 ⟶ 2,602:
print i
i: i + 1
]</
=={{header|Retro}}==
Retro uses signed integer values.
<
=={{header|REXX}}==
<
/*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,242 ⟶ 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.*/</
=={{header|Ring}}==
<
size = 10
Line 2,263 ⟶ 2,678:
n = n + 1
end
</syntaxhighlight>
=={{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}}==
<
The step method of Numeric takes two optional arguments. The limit defaults to infinity, the step size to 1.
Line 2,273 ⟶ 2,711:
Ruby 2.6 introduced open-ended ranges:
<
=={{header|Run BASIC}}==
<
i = i + 1
print i
wend</
Eventually as it gets larger it becomes a floating point.
=={{header|Rust}}==
{{works with|Rust 1.2}}
<
for i in 0.. {
println!("{}", i);
}
}</
Looping endlessly:
<
use num::bigint::BigUint;
Line 2,303 ⟶ 2,741:
i = i + BigUint::one();
}
}</
=={{header|Salmon}}==
Line 2,309 ⟶ 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).
<
i!;</
or
<
i!;</
or
<
while (true)
{
i!;
++i;
};</
=={{header|Scala}}==
<syntaxhighlight lang
=={{header|Scheme}}==
<
(let loop ((i 1))
(display i) (newline)
(loop (+ 1 i)))
</syntaxhighlight>
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:
<
const proc: main is func
Line 2,351 ⟶ 2,815:
writeln(number);
until number = 2147483647;
end func;</
"Forever":
<
include "bigint.s7i";
Line 2,364 ⟶ 2,828:
incr(number);
until FALSE;
end func;</
=={{header|Sidef}}==
No limit:
<syntaxhighlight lang="ruby">1..Inf -> each {.say}</syntaxhighlight>
=={{header|Smalltalk}}==
<
[
Stdout print:i; cr.
i := i + 1
] loop</
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>).
<
01000000000000000000000000000000 1. 2 to CI goto -1 + 1
11111111111111111111111111111111 2. -1</
=={{header|Standard ML}}==
Line 2,390 ⟶ 2,854:
IntInf.int (arbitrary precision).
<
fun printInts(n) =
(
Line 2,398 ⟶ 2,862:
in
printInts(1)
end;</
{{out}}
Line 2,414 ⟶ 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">
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>
A shorter form of the first line above, using list comprehensions:
<syntaxhighlight lang="supercollider">
i = {:i, i<-(0..) };
</syntaxhighlight>
=={{header|Swift}}==
<
while true {
println(i++)
}</
=={{header|Symsyn}}==
<syntaxhighlight lang="symsyn">
| The following code will run forever
| Symsyn uses a 64 bit signed integer
Line 2,441 ⟶ 2,905:
+ x
go lp
</syntaxhighlight>
=={{header|Tcl}}==
<
while true {puts [incr i]}</
=={{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}}==
<
REM will overflow after 32767
LET N = 0
Line 2,454 ⟶ 3,007:
LET N = N + 1
GOTO 10
</syntaxhighlight>
=={{header|True BASIC}}==
<
DO
Line 2,465 ⟶ 3,018:
LOOP
END</
=={{header|TUSCRIPT}}==
<
LOOP n=0,999999999
n=n+1
ENDLOOP</
=={{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}}==
<
num=0
while true; do
echo $num
num=`expr $num + 1`
done</
=={{header|Ursa}}==
<
# integer sequence
#
Line 2,494 ⟶ 3,115:
out i endl console
inc i
end while</
=={{header|Ursalang}}==
<syntaxhighlight lang="ursalang">
let i = 1
loop {
print(i)
i := i + 1
}
</syntaxhighlight>
=={{header|Vala}}==
<
uint i = 0;
while (++i < uint.MAX)
stdout.printf("%u\n", i);
</syntaxhighlight>
=={{header|Verilog}}==
<
integer i;
Line 2,517 ⟶ 3,147:
$finish ;
end
endmodule</
=={{header|Visual Basic .NET}}==
Line 2,526 ⟶ 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>)
<
Console.WriteLine(i)
Next</
===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.
<
Module Module1
Line 2,576 ⟶ 3,206:
TimeStamp("keypress")
End Sub
End Module</
{{out}}
<pre>1
Line 2,588 ⟶ 3,218:
=={{header|WDTE}}==
<
s.new 0 (+ 1)
-> s.map (io.writeln io.stdout)
-> s.drain
;</
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,603 ⟶ 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.
<
import "./big" for BigInt
Line 2,613 ⟶ 3,243:
Fmt.print("$i", bi)
bi = bi + 1
}</
=={{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}}==
<
(print x)
(integer-sequence-from (+ x 1)) )
(integer-sequence-from 1)</
=={{header|XPL0}}==
<
code CrLf=9, IntOut=11;
int N;
Line 2,630 ⟶ 3,277:
N:= N+1;
until N<0;
]</
=={{header|Yabasic}}==
<
repeat
Line 2,640 ⟶ 3,287:
i = i + 1
until i = 0
end</
Line 2,646 ⟶ 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>.
<
PrintChar equ &BB5A
ld hl,1 ;START AT ONE
Line 2,693 ⟶ 3,340:
adc a,&40
jp PrintChar
;ret</
===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.)
<
PrintChar equ &BB5A
ld ix,NumberRam
Line 2,784 ⟶ 3,431:
NumberRam: ;a 64-bit value, stored little-endian
db 01,00,00,00,00,00,00,00</
=={{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}}==
<
m:=(1).MAX; [1..m].pump(Console.println) // (1).MAX is 9223372036854775807
[1..].pump(100,Console.println) // lazy</
|