title: Print all integers

text:
# Question
Title: Print all integers
Write a program or function which will provably **print all integers exactly once** given infinite time and memory.

Possible outputs could be:

```
0, 1, -1, 2, -2, 3, -3, 4, -4, …

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -2, -3, -4, -5, -6, -7, -8, -9, 10, 11, …

```

This is not a valid output, as this would never enumerate negative numbers:

```
~~0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …~~
```
* The output must be in decimal, unless your language does not support decimal integer (in that case use the natural representation of integers your language uses).
* Your program has to work up to the numbers with the biggest magnitude of the standard integer type of your language.
* Each integer must be separated from the next using any separator (a space, a comma, a linebreak, etc.) that is not a digit nor the negative sign of your language.
* The separator must not change at any point.
* The separator can consist of multiple characters, as long as none of them is a digit nor the negative sign (e.g.  is as valid as just `,`).
* Any supported integer must eventually be printed after a finite amount of time.

### Scoring

This is , so the shortest answer in bytes wins

### Leaderboard

```
var QUESTION_ID=93441,OVERRIDE_USER=41723;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```

```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```

```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```

# Answer
> 22 votes
# Sesos, ~~113~~ 3 bytes

```
0000000: c4ceb9                                            ...

```

Try it online! Check *Debug* to see the generated SBIN code.

### Sesos assembly

The binary file above has been generated by assembling the following SASM code.

```
set numout

jmp ; implicitly promoted to nop
    put,   fwd 1
    sub 1, put
    rwd 1, add 1
; jnz (implicit)

```

# Answer
> 51 votes
## Haskell, 19 bytes

```
do n<-[1..];[1-n,n]

```

Produces the infinite list `[0,1,-1,2,-2,3,-3,4,-4,5,-5,6,-6,7,-7...`

Haskell allows infinite lists natively. Printing such a list will prints its elements one a time forever.

# Answer
> 31 votes
# Brainfuck, 6 bytes

This makes use of the cell wrapping and prints all possible values. In Brainfuck, the native integer representation is by byte value.

```
.+[.+]

```

Try it online!

# Answer
> 31 votes
# Cubix, ~~14~~ 12 bytes

```
.(.\OSo;?.>~

```

Test it online! You can now adjust the speed if you want it to run faster or slower.

### How it works

The first thing the interpreter does is remove all whitespace and pad the code with no-ops `.` until it fits perfectly on a cube. That means that the above code can also be written like this:

```
    . (
    . \
O S o ; ? . > ~
. . . . . . . .
    . .
    . .

```

Now the code is run. The IP (instruction pointer) starts out at the top left corner of the far left face, pointed east. Here's the paths it takes throughout the course of running the program:

The IP starts on the red trail at the far left of the image. It then runs `OSo;`, which does the following:

* `O` Print the TOS (top-of-stack) as an integer. At the beginning of the program, the stack contains infinite zeroes, so this prints `0`.
* `S` Push `32`, the char code for the space character.
* `o` Print the TOS as a character. This prints a space.
* `;` Pop the TOS. Removes the `32` from the stack.

Now the IP hits the `?`, which directs it left, right, or straight depending on the sign of the TOS. Right now, the TOS is `0`, so it goes straight. This is the blue path; `.` does nothing, and the IP hits the arrow `>`, which directs it east along the red path again. `~` takes the bitwise NOT of the TOS, changing it to `-1`.

Here the IP reaches the right edge of the net, which wraps it back around to the left; this again prints the TOS (this time `-1`) and a space.

Now the IP hits the `?` again. This time, the TOS is `-1`; since this is negative, the IP turns left, taking the green path. The mirror `\` deflects the IP to the `(`, which decrements the TOS, changing it to `-2`. It comes back around and hits the arrow; `~` takes bitwise NOT again, turning the `-2` to `1`.

Again the TOS is outputted and a space printed. This time when the IP hits the `?`, the TOS is `1`; since this is positive, the IP turns right, taking the yellow path. The first operator it encounters is `S`, pushing an extra `32`; the `;` pops it before it can cause any trouble.

Now the IP comes back around to the arrow and performs its routine, `~` changing the TOS to `-2` and `O` printing it. Since the TOS is negative again, the IP takes the green path once more. And it just keeps cycling like that forever\*: red, green, red, yellow, red, green, red, yellow..., printing in the following cycle:

```
0 -1 1 -2 2 -3 3 -4 4 -5 5 -6 6 -7 7 -8 8 -9 9 -10 10 ...

```

## TL;DR

This program repeatedly goes through these 3 easy steps:

1. Output the current number and a space.
2. If the current number is negative, decrement it by 1.
3. Take bitwise NOT of the current number.

### Non-separated version, 6 bytes

```
nO?~>~

```

Removing the separation simplifies the program so much that it can fit onto a unit cube:

```
  n
O ? ~ >
  ~

```

* **Note**: Neither program is truly infinite, as they only count up to 252 (where JavaScript starts to lose integer precision).

# Answer
> 21 votes
## Python 2, 27 bytes

```
n=0
while 1:print~n,n,;n+=1

```

Prints `-1 0 -2 1 -3 2 -4 3 ...`

# Answer
> 21 votes
# MATL, 8 bytes

```
0`@_@XDT

```

This uses MATL's default data type, which is `double`, so it works up to `2^53` in absolute value. The output is

```
0
-1
1
-2
2
···

```

**Try it online!**

### Explanation

```
0            % Push 0
  `     T    % Do...while true: infinite loop
   @_        % Push iteration index and negate
     @       % Push iteration index
      XD     % Display the whole stack

```

# Answer
> 20 votes
# Shakespeare Programming Language, 227 bytes

```
.
Ajax,.
Puck,.
Act I:
Scene I:
[Enter Ajax,Puck]
Puck:You ox!
Ajax:Be me without myself.Open thy heart.
Scene II:
Ajax:Be thyself and ash.Open thy heart.Be me times you.Open thy heart.Be me times you.Let us return to scene II.

```

Obviously, this answer is nowhere near winning, but I liked that this is a use case that the SPL is comparatively well suited to.

Explained:

```
// Everything before the first dot is the play's title, the parser treats it as a comment.
.

// Dramatis personae. Must be characters from Shakespeare's plays, again with a comment.
Ajax,.
Puck,.

// Acts and scenes serve as labels. Like the whole play, they can have titles too,
// but for the sake of golfing I didn't give them any.
Act I:

// This scene would've been named "You are nothing"
Scene I:

// Characters can talk to each other when on stage
[Enter Ajax,Puck]

// Characters can assign each other values by talking. Nice nouns = 1, ugly nouns = -1.
Puck: You ox!                 // Assignment: $ajax = -1;
Ajax: Be me without myself.   // Arithmetic: $puck = $ajax - $ajax;
      Open thy heart.         // Standard output in numerical form: echo $puck;

// Working title "The circle of life"
Scene II:

// Poor Ajax always doing all the work for us
Ajax: Be thyself and ash.          // $puck = $puck + (-1);
      Open thy heart.              // echo $puck;
      Be me times you.             // $puck *= $ajax;  (remember $ajax==-1 from scene I)
      Open thy heart.              // echo $puck;
      Be me times you.             // negate again
      Let us return to scene II.   // infinite goto loop

```

As you can see when comparing this code to my answer to the related challenge to count up forever (i.e. print all natural numbers), SPL code length grows rather badly when problem size increases...

# Answer
> 11 votes
## GNU sed, 189 + 2(rn flags) = 191 bytes

This is most likely the longest solution, since sed has no integer type or arithmetic operations. As such, I had to emulate an **arbitrary size** increment operator using regular expressions only.

```
s/^/0/p
:
:i;s/9(@*)$/@\1/;ti
s/8(@*)$/9\1/
s/7(@*)$/8\1/
s/6(@*)$/7\1/
s/5(@*)$/6\1/
s/4(@*)$/5\1/
s/3(@*)$/4\1/
s/2(@*)$/3\1/
s/1(@*)$/2\1/
s/0(@*)$/1\1/
s/^@+/1&/;y/@/0/
s/^/-/p;s/-//p
t

```

**Run:**

```
echo | sed -rnf all_integers.sed

```

**Output:**

```
0
-1
1
-2
2
-3
3
etc.

```

# Answer
> 10 votes
# 05AB1E, ~~9~~ 6 bytes

Saved 3 bytes thanks to Adnan

```
[ND,±,

```

Try it online!

Prints `0, -1, 1, -2, 2 ...` separated by newlines.

# Answer
> 10 votes
# R, ~~25~~ 24 bytes

Golfed one byte thanks to @JDL.

```
repeat cat(-F,F<-F+1,'')

```

Try it online!

Example output:

```
0 1 -1 2 -2 3 -3 4 -4 5 -5 6 -6 7 -7 8 -8 9 -9 10

```

# Answer
> 10 votes
# Brainfuck, 127 bytes

```
+[-->+>+[<]>-]>-->+[[.<<<]>>-.>>+<[[-]>[->+<]++++++++[-<++++++>>-<]>--[++++++++++>->-<<[-<+<+>>]]>+>+<]<<<[.<<<]>>.+.>[>>>]<<<]

```

Try it online!

Given an infinite tape would theoretically run forever.

```
0,1,-1,2,-2,3,-3,4,-4,5,-5,6,-6,7,-7,8,-8,9,-9,10,-10,11,-11,12,-12,13,-13,14,-14,15,-15,16,-16,17,-17,18,-18,19,-19,20,-20,21,-21,22,-22,23,-23,24,-24,25,-25,26,-26,27,-27,28,-28,29,-29,30,-30,31,-31,32,-32,33,-33,34,-34,35,-35,36,-36,37,-37,38,-38,39,-39,40,-40,41,-41,42,-42,43,-43,44,-44,45,-45,46,-46,47,-47,48,-48,49,-49,50,-50,51,-51,52,-52,53,-53,54,-54,55,-55,56,-56,57,-57,58,-58,59,-59,60,-60,61,-61,62,-62,63,-63,64,-64,65,-65,66,-66,67,-67,68,-68,69,-69,70,-70,71,-71,72,-72,73,-73,74,-74,75,-75,76,-76,77,-77,78,-78,79,-79,80,-80,81,-81,82,-82,83,-83,84,-84,85,-85,86,-86,87,-87,88,-88,89,-89,90,-90,91,-91,92,-92,93,-93,94,-94,95,-95,96,-96,97,-97,98,-98,99,-99,...

```

**Uncompressed**

```
+[-->+>+[<]>-]>-->+
[
  [.<<<]>>-.>>+<
  [[-]>[->+<]
    ++++++++[-<++++++>>-<]>--
    [++++++++++>->-<<[-<+<+>>]]>+>+<
  ]<<<
  [.<<<]>>.+.>
  [>>>]<<<
]

```

# Answer
> 9 votes
# ShadyAsFuck, 3 bytes

```
FVd

```

Explanation:

```
F     prints the current cell value (0) and increases it by 1
 V    starts a loop and prints the current value
  d   increases the current value and ends the loop

```

This makes use of the cell wrapping and prints all possible values. In SAF, the native integer representation is by byte value.

# Answer
> 9 votes
# Poetic, 565 bytes

```
even as a child, i had a dream i was a person in the movies
it makes a lot of sense,i did think
o,a million people was an image in mind
i inspire folks to see a comedy
o-m-g,how i am funny
o,i mean i laugh,i cry,i scream,i am the funniest
i made a comedy i was pretty proud of
like a galaxy,i am given a star on a big California byway
i make a movie,i make a sequel to a film i edited
i had a vision i was a celeb;as in,an actor
i had a dream i had a legacy
i am asleep now
i quietly awaken
was it truth,or nothing but a fantasy world?o,a whole lot of doubts for me

```

Try it online!

Outputs the following forever:

`0,1,-1,2,-2,3,-3,4,-4,5,-5,6,-6,7,-7,8,-8,9,-9,10,-10,11,-11,`...

# Answer
> 8 votes
## Batch, 56 bytes

```
@set n=0
:l
@echo %n%
@set/an+=1
@echo -%n%
@goto l

```

Output:

```
0
-1
1
-2
2
-3

```

etc. Works up to 2147483647; 58 bytes if you want (-)2147483648 in the output:

```
@set n=0
:l
@echo %n:-=%
@set/an-=1
@echo %n%
@goto l

```

44 bytes if printing all supported positive integers, then all supported negative integers, then repeating endlessly, is acceptable:

```
@set n=0
:l
@echo %n%
@set/an+=1
@goto l

```

# Answer
> 8 votes
# Bash + GNU utilities, 26

```
seq NaN|sed '1i0
p;s/^/-/'

```

# Answer
> 7 votes
# Java 7, ~~151~~ ~~134~~ ~~122~~ 118 bytes

```
import java.math.*;void c(){for(BigInteger i=BigInteger.ONE,y=i;;i=i.add(y))System.out.println(y.subtract(i)+"\n"+i);}

```

12 bytes saved thanks to *@flawr* (and *@xnor* indirectly)

# After rule change.. (~~59~~ ~~56~~ 63 bytes)

```
void c(){for(int i=0;i>1<<31;)System.out.println(~--i+"\n"+i);}

```

Since in Java `2147483647 + 1 = -2147483648`, we can't simply do `i++` and continue infinitely, since the challenge was to print all numbers once. With the above code with added range, it will instead print all integers from `-2147483648` to `2147483647` once each, in the following sequence: `0, -1, 1, -2, 2, -3, 3, -4, ..., 2147483646, -2147483647, 2147483647, -2147483648`. Thanks to *@OlivierGrégoire* for pointing out Java's behavior regarding `MIN_VALUE-1`/`MAX_VALUE+1`. Try it here.

**Ungolfed & test code:**

Try it here - resulting in runtime error

```
import java.math.*;
class M{
  static void c() {
    for(BigInteger i = BigInteger.ONE, y = i; ; i = i.add(y)){
      System.out.println(y.subtract(i) + "\n" + i);
    }
  }

  public static void main(String[] a){
    c();
  }
}

```

**Output:**

```
0
1
-1
2
-2
3
-3
4
-4
5
-5
...

```

# Answer
> 7 votes
## bc, ~~17~~ 16 bytes

**Edit:** 1 byte less thanks to Digital Trauma.

Adding to the diversity of languages used so far, I present a bc solution that works with integers of **arbitrary size**. A newline is required after the code and it is counted in the bytes total.

```
for(;;){i;-++i}

```

In the first iteration `i` is not defined, but printing it gives 0 to my surprise.

# Answer
> 6 votes
# Ruby, ~~26~~ ~~22~~ ~~19~~ ~~16~~ 15 bytes

Prints numbers separated by newlines. -3 bytes from @manatwork. -3 bytes from @m-chrzan. -1 bytes from @CGOneHanded via upgrading to Ruby 2.7+.

```
0.step{p~_1,_1}

```

Attempt This Online! (with a 5 ms timeout)

# Answer
> 6 votes
# DC (GNU or OpenBSD flavour) \- 16 bytes

This version is not shorter than the version below but should be able to run without the stack exploding in your PC. Nevertheless infinite large numbers will take up infinite amounts of memory... somewhen...

Because of the `r` command it needs GNU-DC or OpenBSD-DC.

```
0[rp1+45Pprdx]dx

```

Test:

```
$ dc -e '0[rp1+45Pprdx]dx' | head
0
-1
1
-2
2
-3
3
-4
4
-5

```

---

# DC \- 16 bytes

A little bit mean now. ;-)

This version is abusing the stack length as counter while letting the stack grow.

```
z[pz45Ppllx]dslx

```

Test:

```
$ dc -e 'z[pz45Ppllx]dslx' | head
0
-1
1
-2
2
-3
3
-4
4
-5

```

---

# DC \- 17 bytes

Without dirty tricks.

```
0[p1+45Ppllx]dslx

```

Test:

```
$ dc -e '0[p1+45Ppllx]dslx' | head
0
-1
1
-2
2
-3
3
-4
4
-5

```

# Answer
> 6 votes
## JavaScript, ~~29~~ 26 bytes

### Non-infinite version, 26 bytes

*Saved 3 bytes thanks to ETHproductions*

```
for(n=1;;)alert([1-n,n++])

```

will display all integers between -9007199254740991 and 9007199254740992.

### Infinite version (ES6), ~~114~~ 112 bytes

*Saved 2 bytes thanks to ETHproductions*

```
for(n=[-1];1;alert(n[a||n.unshift(1),0]?(x=n.join``)+' -'+x:0))for(i=n.length,a=0;i--;a=(n[i]+=1-a)>9?n[i]=0:1);

```

will display all integers, given infinite time and memory.

# Answer
> 6 votes
# Powershell, ~~20~~ ~~19~~ 18 bytes

Improved by stealing shamelessly from TimmyD's answer

```
0;for(){-++$i;$i}

```

Output:

```
0
-1
1
-2
2
-3
3
-4
4

```

Old version:

```
for(){-$i;$i++;$i}

```

Not sure why tbh, but -*undeclared variable* (or -$null) is evaluted as 0, which saved us 2 bytes in this version...

# Answer
> 6 votes
# C# 74 bytes

```
class P{void Main(){for(var x=0m;;System.Console.Write(x+++","+-x+","));}}

```

---

```
class P
{
    void Main()
    {
        for(var x = 0m; ; System.Console.Write(x++ + "," + -x + ","));
    }
}

```

Output:

```
0,-1,1,-2,2,-3,3,-4,4,-5,5,-6,6,-7,7,-8,8,-9,9,-10,10,...

```

Try it:

`dotnetfiddle.net` (limited to 1000)

# Answer
> 6 votes
# JavaScript (ES5), 32 31 30 29 bytes

```
for(i=0;;)[i++,-i].map(alert)

```

Prints `0 -1 1 -2 2 -3 3 -4 4 -5 5 ...`

Saved 1 byte thanks to Patrick Roberts! Saved 2 bytes thanks to Conor O'Brien!

# Answer
> 6 votes
## Labyrinth, 9 bytes

```
!`
\:"
 (

```

Try it online!

This also works and is essentially the same:

```
 "
`:(
\!

```

### Explanation

The control flow in this code is rather funny. Remember that the instruction pointer (IP) in a Labyrinth program follows the path of non-space characters and examines the top of the stack at any junction to decide which path to take:

* If the top of the stack is positive, turn right.
* If the top of the stack is zero, keep moving straight ahead.
* If the top of the stack is negative, turn left.

When the IP hits a dead end, it turns around (executing the command at the end only once). And the IP starts in the top left corner moving east. Also note that the stack is implicitly filled with an infinite amount of zeros to begin with.

The program starts with this short bit:

```
!    Print top of stack (0).
`    Multiply by -1 (still 0).
:    Duplicate.

```

Now the IP is at the relevant junction and moves straight ahead onto the `(` which decrements the top of the stack to `-1`. The IP hits a dead end and turns around. `:` duplicates the top of the stack once more. Now the top of the stack is negative and the IP turns left (west). We now execute one more iteration of the main loop:

```
\   Print linefeed.
!   Print top of stack (-1).
`   Multiply by -1 (1).
:   Duplicate.

```

This time, the top of the stack is positive, so IP turns right (west) and immediately executes another iteration of the main loop, which prints the `1`. Then after it is negated again, we hit the `:` with `-1` on the stack.

This time the IP turns left (east). The `"` is just a no-op and the IP turns around in the dead end. `:` makes another copy and this time the IP turns south. `(` decrements the value to `-2`, the IP turns around again. With the top of the stack *still* negative, the IP now turns west on the `:` and does the next iteration of the main loop.

In this way, the IP will now iterate between a tight loop iteration, printing a positive number, and an iteration that goes through both dead ends to decrement the value before printing a negative number.

You might ask yourself why there's the `"` on the second line if it doesn't actually do anything: without it, when the IP reaches `:` on a negative value, it *can't* turn left (east) so it would turn right (west) instead (as a rule of thumb, if the usual direction at a junction isn't available, the IP will take the opposite direction). That means the IP would also never reach the `(` at the bottom and we couldn't distinguish positive from negative iterations.

# Answer
> 5 votes
# Java, ~~65~~ 54 bytes

```
i->{for(;;)System.out.print(i+++" "+(-i<i?-i+" ":""));

```

# Ungolfed test code

```
public static void main(String[] args) {
    Consumer<Integer> r = i -> {
        for (;;) {
            System.out.print(i++ + " " + (-i < i ? -i + " " : ""));
        }
    };

    r.accept(0);
}

```

# Answer
> 5 votes
**C#, 83 bytes**

```
void f(){for(decimal n=0;;n++){Console.Write(n+",");if(n>0)Console.Write(-n+",");}}

```

Ungolfed:

```
void f()
{
  for (decimal n=0;;n++)
  {
    Console.Write(n + ",");
    if (n > 0) Console.Write(-n + ",");
   }
}

```

Outputs:

```
0,1,-1,2,-2,3,-3,4,-4,5,-5,6,-6.......

```

# Answer
> 5 votes
# C# ~~86~~ 66 bytes

New answer:

```
void b(){for(var i=0;;i++)Console.Write(i==0?","+i:","+i+",-"+i);}

```

Clear:

```
void b()
{
    for(var i=0;;i++)
        Console.Write(i == 0 ? "," + i : "," + i + ",-" + i);
}

```

Old answer (86 bytes):

```
void a(){Console.Write(String.Join(",",Enumerable.Range(int.MinValue,int.MaxValue)));}

```

Ungolfed:

```
void a()
{
    Console.Write(String.Join(",", Enumerable.Range(int.MinValue, int.MaxValue)));
}

```

# Answer
> 5 votes
# \>\<\>, ~~19~~ 15 bytes

```
1::1$-naonao1+!

```

This prints the following:

```
0
1
-1
2
-2
3
-3

```

... and so on. The separator is a newline.

Re-written after reading @xnor's answer to use a version of that algorithm. Starting at `n=1`, the program prints `1-n` and `n`, each followed by a newline, before incrementing `n`. After overflowing the maximum value the program will end with an error of `something smells fishy...`. Exactly when this will happen depends on the interpreter implementation.

---

Previous version:

```
0:nao0$-:10{0(?$~+!

```

Starting at 0, the program loops indefinitely. On each loop, the current value is printed along with a newline. It is then negated, and incremented if positive.

# Answer
> 5 votes
# J, 25 bytes

```
([:$:1:`-`(1+-)@.*[echo)0

```

Works on the online site, but I can't verify it on computer yet. Prints numbers like:

```
0
1
_1
2
_2
3
_3
4

```

etc.

# Answer
> 5 votes
# Vim, 19 keystrokes

```
i0<cr>1<esc>qqYpi-<esc>p<C-a>@qq@q

```

Creates a recursive macro that duplicates a number, makes it negative, prints the original number again and increments it.

# Answer
> 5 votes
# Brachylog, 2 bytes

```
ẉ⊥

```

Try it online!

```
ẉ     Print with a newline
      the input,
 ⊥    then try again.

```

Since the program is given no input, the main predicate's input variable is left unconstrained. At first, it is assumed to be 0, but when execution hits , it backtracks to the only possible point of failure: the choice of value for the input variable. So then it tries 1, and -1, and every other integer, printing each one separated by newlines forever because  always forces backtracking, and the effect of  is executed immediately.

# Answer
> 4 votes
# Pyke, ~~7~~ 2 bytes

```
~I

```

Try it here!

### 7 bytes

```
oDID_)r

```

Try it here!

If printing +-0 is ok, `oD_r`

# Answer
> 4 votes
# Jelly, 5 bytes

```
Ṅ~ṄNß

```

Try it online!

### How it works

```
Ṅ~ṄNß  Main link. Argument: n. Implict argument: 0

Ṅ      Print n and a linefeed.
 ~     Apply bitwise NOT, yielding -(n + 1).
  Ṅ    Print -(n + 1) and a linefeed.
   N   Negate, yielding n + 1.
    ß  Recursively call the main link with argument n + 1.

```

# Answer
> 4 votes
# SQL, 84 76 Bytes

*Saved 8 Bytes thanks to steenbergh :)*

Golfed:

```
DECLARE @n INT SET @n= 1 WHILE 1=1 BEGIN PRINT 1-@n PRINT @n SET @n=@n+1 END

```

Ungolfed:

```
DECLARE @n INT
SET @n= 1
WHILE 1=1
BEGIN
PRINT 1-@n
PRINT @n
SET @n=@n+1
END

```

Prints:

```
0
1
-1
2
-2
3
-3
4
-4
5
-5
...

```

# Answer
> 4 votes
# Husk, 2 bytes

```
İZ

```

Try it online!

I know Husk is created after the post of the challenge but I think it is still worth mentioning.

# Answer
> 4 votes
# MarioLANG, 17 bytes

```
:<
+"
)(
-:
>!
=#

```

Try it online!

Vertical loops are normally shorter in MarioLANG. This outputs:

```
0 -1 1 -2 2 -3 3 -4 4 -5 5 -6 6 -7 7 -8 8 -9 9 -10 10 -11 11 .......

```

# Answer
> 4 votes
# Pyth, 6 bytes

```
0f!
_

```

Try it online!

In string representation, this is `"0f!\n_\n"`.

We print 0 explicitly, then use `f` in "count up from 1 until result truthy" mode, where the function prints the input, negates it, prints that, and then boolean negates the result so `f` will never halt.

# Answer
> 4 votes
# Bash, with no external utilities, and no integer size limits, 210 208 bytes

```
echo 0
while
j=$i@
do
while
k=${j/9@/@0}
[ $k != $j ]
do
j=$k
done
j=${j/0@/1}
j=${j/1@/2}
j=${j/2@/3}
j=${j/3@/4}
j=${j/4@/5}
j=${j/5@/6}
j=${j/6@/7}
j=${j/7@/8}
j=${j/8@/9}
i=${j/@/1}
echo $i
echo -$i
done

```

Try it online!

If you wish to see it run with large integers, initialize i to a large integer.

# Answer
> 4 votes
# Hexagony, 14 bytes

Compacted:

```
 !~{/")!;/;"~{/

```

Formatted:

```
   ! ~ {
  / " ) !
 ; / ; " ~
  { / . .
   . . .

```

Try it online!

Improves upon @Sunny Pun's answer by not using the middle -\> edge branches, but instead uses a more linear control flow, while delimiting with null bytes (didn't see anything against this) which are the default state of memory in Hexagony.

# Answer
> 4 votes
# convey, 14 bytes

```
}"0
 v^0
1-"-}

```

Try it online!

How it works (so cool):

# Answer
> 4 votes
# APOL, 19 bytes

`w(T p(∈) p(-(0 ∈)))`

Pretty self-explanatory.

# Answer
> 4 votes
# Regenerate `-a`, 22 bytes

```
0|($2[0-9]!-?[1-9]())+

```

Attempt This Online!

Thanks to thejonymyster for the idea to use this language to answer this question.

In pretty-printed format:

```
    0
|
    (
        $2       # only matches after $2 has been set
        [0-9]    # all subsequent digits
    !
        -?       # negative or positive
        [1-9]    # first digit
        ()       # capture group $2
    )+           # Repeat the above 1 to infinity times

```

The first main alternative is `0`. Once that has been used, it moves on to the second main alternative, which is split into two sub-alternatives. They are split using `!` instead of `|`, so whichever choice is made will be locked-in once it no longer results in any changes of state.

The first time through, the `$2[0-9]` branch cannot be taken, since `$2` is unset and results in a non-match. So the branch `-?[1-9]()` will be taken – and it results in a change of state: the capture group `$2` becomes set rather than unset.

Due to the change of state, the `(`...`!`...`)` set of alternatives is given another chance to be chosen, if it is repeated. Since `$2` is now set, the first alternative will be taken, and this locks it in – from this point forward, it is the only alternative that will be taken.

...or at least, that's my current best understanding of how it works. I don't think it's correct, otherwise `0|($4($3[0-9]![1-9]())!-?()){2,}` (32 bytes) should do the same thing as the 22 byte version, but it doesn't. The `!` operand is undocumented, so it'll take analyzing Regenerate's source code or asking to author to figure out how exactly it works.

...but as it turns out, `0|($2[0-9]!$3[1-9]()!-?()){2,}` (31 chars / 33 bytes), with a zero width joiner inserted after the `-?`, does work, so my explanation may be accurate. The problem may just be that alternatives don't work the same way when they make a zero-width match.

# Regenerate `-a` (staging), 15 bytes

```
0|-?[1-9][0-9]*

```

Attempt This Online!

In the latest version of the language, the obvious solution now works. Before the fix, this would only print nonnegative integers beginning with the digit `1`:

Attempt This Online! \- presumably this link will eventually show the same behavior as the above one, when the new version of Regenerate graduates from staging

# Regenerate `-a`, 12 bytes (10 characters)

```
0|(+)-?#1

```

Attempt This Online!

If outputting invisible whitespace is allowed, this can be used to "cheat":

```
    0
|
    (+)  # $1 = Repeat U+200D (Zero Width Joiner), 1 to infinity times
    -?   # Optionally match a negative sign
    #1   # Match the length of $1 as a number in decimal

```

Regenerate would theoretically keep printing all integers indefinitely, but in practice it stops due to hitting a recursion limit. It can't actually repeat anything more than 994 times on Attempt This Online, for example.

# Answer
> 3 votes
# Prolog (SWI), 33+3 = 36 bytes

```
A*B:-C is B-A,writeln(C),C*(1-B).

```

Try it online!

Called as `0*0.`

Prints `0, 1, -1, 2, -2 ...` separated by newlines.

Saved 5 bytes thanks to SQB
Saved 16 bytes thanks to user3744156

# Answer
> 3 votes
## PowerShell v2+, 26 bytes

```
0;for(;$i-lt2gb){$i;-++$i}

```

Covers all 32-bit `[int]` values, as that's the default number type for PowerShell. Prints `0`, then loops up to `2gb` (which is a special operator, not a constant, yielding 2147483648). Must be called as a full program so that `$i` properly defaults back to `$null`.

### Example

```
PS C:\Tools\Scripts> 0;for(;$i-lt2gb){$i;-++$i}
0
-1
1
-2
2
...
2147483646
-2147483647
2147483647
-2147483648

```

---

### Truly infinite, 34 bytes

```
0;for([bigint]$i=1;;$i+=1){$i;-$i}

```

For a truly infinite variation that will (eventually) print every single integer in existence given infinite time and memory, try the above. We simply tack on the `[bigint]` cast and change slightly how the loop is calculated.

# Answer
> 3 votes
# \>\<\>, 11 bytes

```
lnao0l-naol

```

Try it online! Uses the stack length as a counter.

```
ln             Output length of stack
  ao           Output newline
    0l-n       Output 0 - (length of stack + 1), +1 because of the additional 0
        ao     Output newline
          l    Push length of stack, increasing the stack length by 1
               (Implicit loop since ><> is toroidal)

```

# Answer
> 3 votes
# Perl, 19 bytes

```
perl -E 'say-$}while say$}++'

```

In reality will get stuck when at some huge number `$}` switched to floating point and starts losing precision.

This 27 byte version will ***really*** print forever:

```
perl -E 's//0/;say"-".++$_ while say'

```

# Answer
> 3 votes
# Hexagony, ~~22~~ 18 bytes

```
!(~2016}Q2;'Oct4!~

```

Try it Online!

Excuse me for keep editing.. After typing the explanations I managed to squeeze.. not so squeeze this into a 3-hexagon and there are still plenty of space to put today's date in.

## Old Answer

Try it Online! (old answer)

I have a love at first sight with this language...

```
!(._/;'<~.2/~/!}Q/>.$>

```

## Expanded

```
   ! ( . _        When n<=0, print (-ve number) and n--
  / ; ' < ~       After printing ,
 . 2 / ~ / !      If n<=0, n=-n and print (the +ve number)
} Q / > . $ >     Else n=-n and go into auto-if
 . . . . . .
  . . . . .
   . . . .        When n>0, do nothing as the number is printed at line 3

```

The basic algorithm is,

**Loop**: `print`, `if(n<=0) n--`, `n=-n`, then `print ,`

I come into this answer with the thought of using implicit `if` by going out of the corner:

```
   ! ( . .
  . . . . .
 . . . . . .
. ~ } Q 2 ; '
 . . . . . .
  . . . . .
   ! . . .

```

However it is real using a lot of bytes for no-ops in putting the `!` there, and in the hope of getting the `!` (print) back into the main middle loop, I found it hard to print the 0 since the `if(n<=0)n--` is run before the main loop for printing. So keep drawing on a whiteboard (*it is easier to overwrite a byte on a whiteboard than most of other tools*) I came up with the above which puts one extra `~` (negation) after branching at line 2 but saves me from using the no-ops at the end.

Anyone who can guide me how to make beautiful Hexagony explanation images?

# Answer
> 3 votes
# C (gcc), ~~40 38~~ 36 bytes

```
main(i){for(;printf("%d ",i),i++;);}

```

Try it online!

### Explanation:

The first argument to `main()` is `argc`, which is 1 if the program is run without additional parameters. When we reach the max positive integer, `i` wraps around and becomes negative. The program stops when `i==0`, after printing it.

Thanks @ceilingcat for -3 bytes

# Answer
> 3 votes
## Wumpus, 8 bytes

```
=nON
=)N

```

Try it online!

Prints the integers in the order `-1, 0, -2, 1, -3, 2, ...` using linefeed separation.

### Explanation

Let's look at the actual grid first:

The instruction pointer starts in the top left corner moving east and will reflect off the edge whenever it reaches a boundary of the code. Hence, this program loops through the code indefinitely, but we reuse the single `O` (because it's executed both before and after entering the top right corner).

So the loop body looks like this:

```
=nONON)=

```

Let's go through this:

```
=   Duplicate the top of the stack. Initially, this is an implicit zero,
    but in general this will be the non-negative number of each pair we print.
n   Bitwise NOT. Turns the copy of n into -n-1.
O   Output -n-1.
N   Output a linefeed.
O   Output n.
N   Output a linefeed.
)   Increment n to n+1.
=   Duplicate it (because one copy of it will be printed in the next iteration).

```

# Answer
> 3 votes
# V (vim), 18 bytes

```
i0<esc>qqYp<c-a>Yi-<esc>p@qq@q

```

Try it online!

a small improvement by shuffling around the loop and removing the 1 from James' answer.

# Answer
> 3 votes
# Dyalog APL, ~~18~~ ~~17~~ ~~15~~ ~~14~~ 12 bytes

```
{∇-⎕←1-⎕←⍵}0

```

Try it online!

```
{       Begin function
  ∇     Call recursively with new argument and repeat: -⍵-1
  -     Negate sign to make it negative again: -⍵-1
  ⎕←    Print current value: ⍵+1
  1-    Subtract it from 1, flipping the sign and incrementing the absolute value: ⍵+1
  ⎕←    Print current value: -⍵
  -     Negate sign to make it negative: -⍵
  ⍵     Argument to function, starts at 0 and increments by one each time: ⍵
}       End function
0       Call function with 0

```

Thanks to @Razetime & @Adám for their help golfing my original 18 bytes to 12. It started as `⎕←0⋄{∇⊃1+|⎕←-⎕←⍵}1` and is far more elegant now, not to mention more competitive!

# Answer
> 3 votes
# Vyxal, 5 bytes

```
{N…ꜝ…

```

Try it Online!

```
{     # Forever...
 N    # Negate
  …   # Print
   ꜝ  # ~
    … # Print

```

# Answer
> 2 votes
# PHP, ~~28~~ 27 bytes

```
for(;1;)echo 1-++$i," $i ";

```

As aross pointed out in the comments this only outputs `PHP_INT_MIN` (or indeed `PHP_INT_MIN + 1`) on a 32 bit implementation of php.

Old versions:

```
for(;++$i;)echo 1-$i," $i ";

```

If a leading space is allowed then

```
for(;++$i;)echo" $i ",1-$i;

```

Is 1 byte shorter. (same length as new version)

# Answer
> 2 votes
## Retina, ~~21~~ 19 bytes

```
{M*`.
^
1
*`.+
-$.&

```

Try it online! (Takes about a minute before you see anything.)

# Answer
> 2 votes
# Octave, 30 bytes

```
x=0;while 1;disp([x++;-x]);end

```

Explanation:

```
x=1;       % Initialize x to 1
while 1;   % Infinite loop since 1 == true
[x++,-x]   % x, then post increment and show the negative version
disp(___)  % display it
end

```

Prints the following sequence, starting from 0:

```
   0
  -1
   1
  -2
   2
  -3
   3
   .
   .

```

# Answer
> 2 votes
## MATLAB 64 bytes

As a start, with nothing clever:

```
fprintf('0');a=int64(1);while(1) fprintf(' %d',[a -a]);a=a+1;end

```

Enter at the console, generates 0 1 -1 2 -2...

There must be a better way than this! Come on, folks...

# Answer
> 2 votes
## Powershell, ~~26~~ 19 Bytes

```
for(){($b++);$b*-1}

```

updated because I should have done it months ago.

very straightforward, takes a variable `$a`, initializes as 0, then initiates an infinite loop with `while(1){}` and then displays the current value `$a` \- increments it `$a++` and displays the negative version of it `$a*-1`

output is automatically on a new line for each display, so the resulting output is:

```
0
-1
1
-2
2
-3
3
-4

```

# Answer
> 2 votes
# ~~PHP, 24 26 bytes~~

(24 bytes not displaying PHP\_INT\_MIN)

```
for(;;)echo-$i++," $i ";

```

Output : `0 1 -1 2 -2 3 -3 4 -4 5 -5 6 -6 7 -7 8 -8 9 -9 10 -10 ...`

As `$i` is not defined, you have to cast it as integer (with `-` or `+0`)

(26 bytes not displaying PHP\_INT\_MIN)

```
for(;;)echo$i+++0," -$i ";

```

Output : `0 -1 1 -2 2 -3 3 -4 4 -5 5 -6 6 -7 7 -8 8 -9 9 -10 10 ...`

# Answer
> 2 votes
## Befunge 93, 8 bytes

```
:.-:0`!-

```

Try it online!

### Explanation

Befunge's stack is thankfully filled with an implicit infinite amount of zeros, and printing a number also prints a trailing space.

```
:.    Print the top of the stack.
-     Subtract it from the implicit zero underneath, effectively multiplying by -1.
:0`   Check whether its greater than 0.
!     Logical NOT. Gives 0 if the current value is positive and 1 otherwise.
-     Subtract from current value.

```

The source code is toroidal so this program repeats indefinitely.

# Answer
> 2 votes
# Lua , 43 Bytes

```
i=1;while 1 do print(1-i);print(i);i=i+1 end

```

# Answer
> 2 votes
# C# 222 bytes (Infinite output version)

Being more fond of the infinite output version of the print-all-integers program, I created this.

```
IEnumerable<string>g(){var w=new[]{'0'};yield return "0";while(true){var c=true;for (var r=w.Length-1;c&&r>=0;r--)if(c=++w[r]==58)w[r]='0';var b=new string(w);if(c)w=(b="1"+b).ToArray();yield return b;yield return "-"+b;}}

```

This function continuously returns the next greater positive and negative integers. The values are not limited by the integer type but since integers are used to handle the array, the program will fail when the number has more than 2,147,483,647 digits. However, it will most likely run out of memory long before that happens.

Usage:

```
static void Main(string[] args)
{
    foreach (var n in g())
    {
        Console.WriteLine(n);
    }
}

```

# Answer
> 2 votes
## Actually, 7 bytes

```
01W;±@u

```

This solution requires infinite time to actually print anything. Finite memory will cause an out of memory error and premature printing. No TIO link for obvious reasons.

Explanation:

```
01W;±@u
0        push 0
 1       push 1
  W      infinite loop:
   ;       duplicate
    ±      unary negate
     @     swap with positive
      u    increment

```

---

This solution works for 8 bytes, prints a finite amount of numbers in a finite amount of time, and uses significantly less memory (the memory used doesn't start growing until after `INT_MAX` is printed, at which point Python seamlessly transitions to arbitrary-precision integers).

```
0■~W■±■~

```

Try it online! (only prints up to around 9292 due to timeout).

Explanation:

```
0■~W■±■~
0         push 0
 ■        print entire stack without popping (just the 0)
  ~       bitwise negate (~n is equivalent to -n-1)
   W      infinite loop:
    ■       print stack without popping
     ±      unary negate
      ■     print without pop
       ~    bitwise negate

```

# Answer
> 2 votes
## Burlesque, 12 bytes

```
0R@J-1?*_+[-

```

You can try a restricted version here.

```
0R@  Range from 0 to Infinity
J    Duplicate
-1?* Multiply one Block by -1 (negative integeres)
_+   Concatenate
[-   Tail to Remove the duplicate zero

```

# Answer
> 2 votes
### Brainfuck, 10 bytes

```
.+[>-.<.+]

```

Does *not* rely on cell wrapping to print the negative values. *Does* rely on accepting the cell value, which is commonly printed as a character by converting it to ASCII, to be the value to print.

Try it online!

# Answer
> 2 votes
# Java, 49 bytes

```
o->{for(int n=1<<31;n<0;)o.println(n+"\n"+~n++);}

```

Notes:

* `o` is a `java.io.PrintStream` but its import is not required given it's the parameter of a lambda expression.
* This must be run on a Unix machine to properly use the same separator.

## Ungolfed

```
import java.io.PrintStream;
import java.util.function.Consumer;

public class Main {
    public static void main(String[] args) {
        Consumer<PrintStream> func = o -> { // define the output and start the function.
          for (int n = 1 << 31; n < 0; n++) { // for each negative integer increasing from Integer.MIN_VALUE
            o.println(n + "\n" + ~n); // Print the negative number and its complement to 2 value.
          }
        };
        func.accept(System.out);
    }
}

```

## Result

```
-2147483648
2147483647
-2147483647
2147483646
-2147483646
2147483645
-2147483645
2147483644
-2147483644
2147483643
-2147483643
2147483642
-2147483642
2147483641
-2147483641
2147483640
...
-7
6
-6
5
-5
4
-4
3
-3
2
-2
1
-1
0

```

# Answer
> 2 votes
# R, ~~33~~ 29 bytes

```
x=0;while(T)cat("",-x,x<-x+1)

```

# Output (for \< 10)

```
0 1 -1 2 -2 3 -3 4 -4 5 -5 6 -6 7 -7 8 -8 9 -9 10

```

# Explanation

It works because x is set to 0, then prints -0 which displays as 0. It then increments and prints that, giving 1. The next element is the negative value of the last which is -1 and so on...

EDIT: Cut it down by 4 bytes after I realised that I could just have it loop forever. In R, `T` is `TRUE` by default.

# Answer
> 2 votes
# C 331 bytes

Note that this outperforms the long version as it really can do as many as memory will permit. It seems like it is bounded by strings of length max(size\_t) which is true, but also definitionally the maximum memory that c will let us grab. Unfortunately it is very slow since it thrashes memory.

```
#include<stdlib.h>
int main(_,a,b,c,d,e)char*a,*b;size_t c,d,e;{return(_==1?printf("0\n"),main(2,0,0,1,0,0):_==2?main(3,"",0,c,0,0),main(2,0,0,c+1,0,0):_==3?(c?d=strlen(a),b=malloc(d),memcpy(b,a,d),b[d+1]=0,main(4,b,0,d,c-1,9),free(b),0:(*a-48?printf("%s\n-%s\n",a,a):0)):(e+1?a[c]=e+48,main(3,a,0,d,0,0),main(4,a,0,c,d,e-1):0));}

```

Prints 0, then 9,8,7,... then 99,98,97... etcetera. Can save 3 characters if we assume we don't care about output buffering (swapping \n for a space).

Process:

## Initial

```
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// prints base 0...0, base 0...1, etc with remaining digits after it.
void print_digit_permutations(char *base, size_t remaining)
{
    int i;
    char *newbase = malloc(strlen(base)+1);

    if (!remaining) {
        if (*base != '0')
            printf("%s\n-%s\n",base,base);
        return;
    }

    for (i = 0; base[i]; ++i) {
        newbase[i] = base[i];
    }
    newbase[strlen(base)+1] = 0;

    for (i = 0; i < 10; ++i) {
        newbase[strlen(base)] = i + '0';
        print_digit_permutations(newbase, remaining-1);
    }

    free(newbase);
}

int main()
{
    char *base = "";
    size_t i = 0;

    printf("0\n");

    for (;;) {
        print_digit_permutations(base, ++i);
    }

    return 0;
}

```

## Unrolled

```
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void base_copy(char *newbase, char *base)
{
    if (*base) {
        *newbase = *base;
        base_copy(newbase+1,base+1);
    }
}

void print_digit_permutations(char*,size_t);
void print_all_digits(char *newbase, size_t baselen, size_t remaining, size_t count)
{
    if (count+1) {
        newbase[baselen] = count + '0';
        print_digit_permutations(newbase,remaining);
        print_all_digits(newbase,baselen,remaining,count-1);
    }
}

void print_digit_permutations(char *base, size_t remaining)
{
    int i;
    char *newbase = malloc(strlen(base)+1);

    if (!remaining) {
        if (*base != '0')
            printf("%s\n-%s\n",base,base);
        return;
    }

    base_copy(newbase,base);
    newbase[strlen(base)+1] = 0;

    print_all_digits(newbase,strlen(base),remaining-1,9);

    free(newbase);
}

void all(size_t size)
{
    print_digit_permutations("",size);
    all(size+1);
}

int main()
{
     printf("0\n");
     all(1);

     return 0;
}

```

## Flat

```
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int print_digit_permutations(char *base, char *newbase, size_t remaining, size_t baselen, size_t _);
int print_all_digits(char *newbase, char *_, size_t baselen, size_t remaining, size_t count)
{
    return (count+1?
                newbase[baselen] = count + '0',
                print_digit_permutations(newbase,newbase,remaining,0,0),
                print_all_digits(newbase,newbase,baselen,remaining,count-1)
                :
                0);
}

int print_digit_permutations(char *base, char *newbase, size_t remaining, size_t baselen, size_t _)
{
    return (remaining?
            baselen=strlen(base),
            newbase = malloc(baselen),
            memcpy(newbase,base,baselen),
            newbase[baselen+1] = 0,
            print_all_digits(newbase,newbase,baselen,remaining-1,9),
            free(newbase),
            0
            :
            (*base-'0'?printf("%s\n-%s\n",base,base):0));
}

int all(char *_, char *_2, size_t size, size_t _3, size_t _4)
{
    return print_digit_permutations("","",size,0,0),
           all(_,_2,size+1,_3,_4);
}

int main()
{
    return printf("0\n"),all("","",1,0,0);
}

```

## Main

```
#include <stdlib.h>
/* _ values:
 *
 * 1 - main
 * 2 - all
 * 3 - print_digit_permutations
 * 4 - print_all_digits
 */
int main(_,a,b,c,d,e)char*a,*b;size_t c,d,e;{
    switch (_) {
        case 1:
            return printf("0\n"),main(2,0,0,1,0,0);
        case 2:
            return main(3,"",0,c,0,0),main(2,0,0,c+1,0,0);
        case 3:
            return (c?
                    d=strlen(a),
                    b=malloc(d),
                    memcpy(b,a,d),
                    b[d+1]=0,
                    main(4,b,0,d,c-1,9),
                    free(b),
                    0
                    :
                    (*a-'0'?printf("%s\n-%s\n",a,a):0));
        case 4:
            return (e+1?
                        a[c]=e+'0',
                        main(3,a,0,d,0,0),
                        main(4,a,0,c,d,e-1)
                        :0);
    }
}

```

And after removing whitespace and making a few other small changes we arrive at the initial golfed code. It is interesting that the 'proper' initial code is the second shortest at just over 700 bytes.

# Answer
> 2 votes
# PHP, ~~27~~ 26 bytes

Note that my answer actually outputs `PHP_INT_MAX` and `PHP_INT_MIN`, whereas others don't.

```
for(;;)echo+$i,_,~+$i++,_;

```

Run like this:

```
php -d error_reporting=30709 -r 'for(;;)echo+$i,_,~+$i++,_;';echo

```

This iterates from `0` to `PHP_INT_MAX`, obviously using post-increment to get the full range and not have an off-by-one error. Then get the negative range by ~~`XOR`-ing with `-1`~~ binary negation.

# INT\_MAX and INT\_MIN

A signed integer actually has a 1 bigger range of negative values than positive values. In the case of 64-bit int (PHP default on 64-bit systems) it's -922337203685477580**8** upto 9223372036854775808**7** inclusive. Many answers stop at -922337203685477580**7**, which is 1 short.

To see the tail of the output (with `PHP_INT_MAX` and `PHP_INT_MIN`), just do this:

```
php -d error_reporting=30709 -r 'for($i=PHP_INT_MAX-5;is_int($i);)echo+$i,_,~+$i++,_;';echo

```

The `is_int` is strictly not needed, it just makes sure the loop stops when `$i` exceeds `PHP_INT_MAX` and becomes a float, outputting junk for all eternity.

# Tweaks

* Use binary negation instead of xor with `-1`. Requires another cast to `int` to handle the `null` case. Saved a byte.

# Answer
> 2 votes
# LI, ~~16~~ 7 bytes

New solution:

```
R-0P-1P

```

I feel kinda silly for not realizing I could have done this before. I'm keeping the other one because it shows off more flow control and more functions.

LI is a (very) WIP language that relies primarily on recursion. Every program in LI must take in user-provided input, so the given program here accepts LI's "null" input of `0`.

The current Python interpreter is just barely enough to meet the specifications of this challenge, albeit wordy; I'm working on a Racket interpreter that would be able to meet the specs of this challenge with three bytes, but unfortunately it's not even close to challenge-ready.

Explanation:

```
      P    Print input
    -1     (1 - input)
   P       Print that too
 -0        (- (1 - input))
R          Rerun program with new input

```

Old solution:

```
R?>0i-0PyPi-0PYP

```

Roughly, this program translates to:

```
R                        Recurse program with input:
                 P        print-return (implicit input)
                Y         Increment input
               P          Print incremented
             -0           Invert sign
                          = -(i+1)
 ?>0i                   if i is not negative.
      -0PyPi            If i is negative, do the same but decrement (y) instead of increment.

```

*For both solutions, output is of the following format:*

```
0
1
-1
2
-2
3
-3
...

```

The default interpreter will run out of memory at -3338 (3342 with the new solution), if you're curious.

# Answer
> 2 votes
# Rust, 39 bytes

```
||for i in 0..{print!(" {} {}",i,-1-i)}

```

This uses i32. adding i64 right behind the zero would make it use that instead at a cost of 3 more bytes. Rust has no bignum types in the standard library. When overflowing, this will either panic or quietly wrap around, depending on compiler options.

# Answer
> 2 votes
**q KDB+, 25 bytes**

```
n:-0W;while[n<0W;0N!n+:1]

```

Set n to negative infinity.

```
n:-0W

```

Increment and output n.

```
0N!n+:1

```

Loop until n \< infinity.

```
n<0W

```

**Possible alternate 17 bytes**

```
(0N!1+)\[0W>;-0W]

```

Uses the \ (iterate) dyadic function to apply left hand side (plus 1 then output) from negative infinity (-0W) to infinity(0W).

Only problem is that it may throw a wsfull error eventually or at the very end after outputting all the integers.

# Answer
> 2 votes
# Python 2, 32 bytes

```
i=0
while 1:print i;print~i;i+=1

```

# Answer
> 2 votes
# SmileBASIC, 20 bytes

```
@L?N,-N-1N=N+1GOTO@L

```

A very boring answer.

Alternative:

```
@L?N
INC N?-N
GOTO @L

```

# Answer
> 2 votes
# tcl, 35

```
puts 0
while 1 {puts [incr i]\n-$i}

```

demo

# Answer
> 2 votes
# Add++ v0.2, 23 bytes

This is the current version on TIO. The latest should be able to do it in less but it is untested so I decided not to post it.

```
O
V
+1
W,G,+1,O,~,O,~,V

```

Try it online!

How does it work?

```
O      Output the accumulator (x) as a number (0)
V      Save x in the second stack
+1     Add one to x
W,     While x is true:
  G,     Set x to the popped item from the second stack
  +1,    Add 1 to x
  O,     Output x as a number
  ~,     Negate x
  O,     Output x as a number
  ~,     Negate x
  V      Save x in the second stack

```

# Add++ v5.10, 13 bytes

```
Dx,O,#,+1,O,#

```

Try it online!

# Answer
> 2 votes
# \>\<\>, ~~17~~ 16 Bytes

```
0:n1+ao:0$-nao0?

```

Could shave off 4 bytes, at the cost of separation in the output.

Current output:

```
0
-1
1
-2
2
...

```

Explanation:

```
0:n                          | Puts 0 on the stack, duplicates it, and prints it.
   1+                        | Increments the value
     ao                      | Prints a new line.
       :0$-n                 | Duplicates the value, prints it negative.
            ao               | Print a new line.
              0?             | Skip the next command (pushing 0), repeat.

```

Previous solution:

```
0:n1+ao:0$-nao01.

```

Teleports to the command after the 0, instead of just skipping it.

# Answer
> 2 votes
# GolfScript, ~~16~~ 14 bytes

```
1{.p.1\-p).}do

```

# Explanation:

```
1              # Set counter to 1
 {        .}do # While counter is nonzero:
  .p           # Print counter
    .1\-p      # Print counter - 1
         )     # Increment counter by 1

```

Try it online!

# Answer
> 2 votes
# Wren, 50 bytes

```
var n=0
while(n)n=-System.print(1-System.print(n))

```

Try it online!

## Explanation

```
var n=0 // Set n as 0
while(n)                                   // While n is an integer:
                          System.print(n)  // Output n
           System.print(1-               ) // Output 1-n
        n=-                                // Set n as the number negated

```

# Answer
> 2 votes
# Runic Enchantments, 24 bytes

```
8?;>0$' $01+:$' $Z:$' $Z

```

Try it online!

`' $` is just as long as any other way of printing a character (such as `ak$`) so with a required separator, that's as short as it gets.

Will print forever until the value exceeds the binary representation and sign-overflows (which is acceptable for questions with an infinite memory assumption), whereupon it will repeat.

# Answer
> 2 votes
## `d`, ~~6~~ 5 bytes

Newline-separated. Look ma, no bitwise magic!

```
▲h(2Z

```

## Explanation

Decompressed:

```
0      % Print 0 (the implicit not-given operand, to be precise)
 i   E % In the range 1..infinity...
  a    % Explicit loop variable
   P   % Print the number with a newline
    _  % Negate the number
       % Implicit print on each iteration
       % Make sure that the second-to-top executes (this is now implicit)

```

# Answer
> 2 votes
# x86-16, IBM PC DOS, 47 bytes

### Binary:

```
00000000: 33c9 bd0a 0050 0bc0 7d09 50b8 2d0e cd10  3....P..}.P.-...
00000010: 58f7 d833 d2f7 f552 410b c075 f658 b40e  X..3...RA..u.X..
00000020: 0c30 cd10 e2f7 b020 cd10 5840 75d7 c3    .0..... ..X@u..

```

Build and test using `xxd -r`

### Unassembled listing:

```
33 C9       XOR  CX, CX         ; clear counter
B3 0A       MOV  BL, 10         ; BX is divisor
        INT_LOOP:
50          PUSH AX             ; save registers
0B C0       OR   AX, AX         ; is AX negative?
7D 09       JGE  DIGIT_LOOP     ; if positive, start digit loop
50          PUSH AX             ; save number
B8 0E2D     MOV  AX, 0E2DH      ; BIOS tty function, '-' char output
CD 10       INT  10H            ; write to console
58          POP  AX             ; restore AX
F7 D8       NEG  AX             ; AX = -AX
        DIGIT_LOOP:
33 D2       XOR  DX, DX         ; clear high word of dividend
F7 F3       DIV  BX             ; AX = quotient, DX = remainder
52          PUSH DX             ; save remainder on stack
41          INC  CX             ; increment counter
0B C0       OR   AX, AX         ; quotient = 0?
75 F6       JNE  DIGIT_LOOP     ; no, keep going
        PRINT_LOOP:
58          POP  AX             ; restore digit in AL
B4 0E       MOV  AH, 0EH        ; BIOS tty function
0C 30       OR   AL, '0'        ; convert to ASCII
CD 10       INT  10H            ; write to console
E2 F7       LOOP PRINT_LOOP     ; loop until all digits displayed
B0 20       MOV  AL, ' '        ; space char
CD 10       INT  10H            ; write to console
58          POP  AX             ; restore counter
40          INC  AX             ; increment to next number
75 D7       JNZ  INT_LOOP       ; loop until 0
C3          RET                 ; return to DOS

```

(This program is basically just an `itoa()` function...)

### Output

A standalone DOS executable. Using default 16-bit integer size for 8088, writes all numbers in decimal to console.

Head:

Tail:

# Answer
> 2 votes
# MathGolf, 8 bytes

```
0Æ∙p~p)∟

```

Try it online.

**Explanation:**

```
0         # Push a 0
       ∟  # Do-while true without popping,
 Æ        # using the following 5 commands:
  ∙       #  Triplicate the top of the stack
   p      #  Pop and print with trailing newline
    ~     #  Take the bitwise-NOT
     p    #  Also pop and print it with trailing newline
      )   #  And increase the top value by 1

```

# Answer
> 2 votes
# LaTeX, 97 bytes

```
\def\f{\typeout0\newcount\n\n=1\loop\typeout{\the\n}\typeout{-\the\n}\advance\n1\ifnum1=1\repeat}

```

Defines a macro `\f` that writes to stdout.

## Explanation

```
\def\f{                % define a macro \f
  \typeout0             % write a 0
  \newcount\n           % define a new counter n
  \n=1                  % set n to 1
  \loop                 % this is like a do-while loop
    \typeout{\the\n}     % write n
    \typeout{-\the\n}    % write -n
    \advance \n 1        % increment n by 1
  \ifnum 1=1            % this is the loop condition, continue if 1=1
  \repeat               % jump to the loop start
}

```

# Answer
> 2 votes
# Turing Machine Code, 460 bytes

This prints the list in Unary so I'm hoping this still counts since, in Turing Machine Code, the concept of a 'number base' isn't built in. I'm going to mull over a base ten solution and post it separately if it exists and I find it.

```
0 * 1 r 2
2 * , r 3
3 * - r 4
4 * 1 r 5
5 * * r 5
5 _ , r 6
6 * * r 6
6 _ 1 * 7
7 * * l 7
7 , , l 8
8 * * l 8
8 - - r 9
9 1 @ r a
8 , , r g
g 1 @ r a
g - - r a
a * * r a
a _ 1 l b
b * * l b
b @ 1 r c
c 1 @ r a
c , , r d
d * * l d
d - - r 6
d , , r e
e * * r e
e _ , r f
f _ - r h
h * * l h
h , , l i
i * * l i
i , , r j
j 1 @ r k
j , , r m
k * * r k
m * * r m
m _ , r n
k _ 1 * o
o * * l o
o , , l p
p * * l p
p , , r q
p @ 1 r j
q * * r q
q _ , r n
n _ 1 r 7

```

Try it online!

# Answer
> 2 votes
# F# (.NET Core), 46 bytes

My first F# golf.

```
let rec c x=
 printf"%d,%d,"(1-x)x
 x+1|>c
c 1

```

Try it online!

# Answer
> 2 votes
# Vyxal, 7 bytes

```
0…{!…N…

```

Try it Online!

# Answer
> 2 votes
# APL, 17 bytes

Pretty self explanatory

```
{∇⊃⎕←(⊢,-)1+⍵}⎕←0

```

# Answer
> 2 votes
# Vyxal, 13 bitsv2, 1.625 bytes

```
Þn

```

Built-in list containing all integers.

Try it Online!

# Answer
> 2 votes
# Befunge-93, 8 bytes

```
.1+::&*.

```

Try it online!

## Explanation

```
v // Make this explanation be able to run (downwards)
. // Print top of stack as integer (if first iteration, stack is initialized at 0, so 0 is the first integer printed)
1
+ // Increment
:
: // Duplicate number so it isn't lost doing operations and printing
&
* // Negate. When input is empty, getting user input with & returns -1.
. // Output negative integer
  // Continue to next iteration, where top of stack (positive integer) will get printed

```

Try it online!

# Answer
> 1 votes
# MATL, 9 bytes

```
0`t_DQtDT

```

You can Try it online! (and let's hope that the process on the server actually terminates once you close your browser...)

Explanation:

```
0             % Push 0 on stack
 `       T    % Start infinite loop
  t_D         % Duplicate top element, negate and display (which consumes the duplicate)
     QtD      % Add 1 to top of stack, duplicate and display (which consumes the duplicate)

```

# Answer
> 1 votes
## **Caché ObjectScript**, 28 bytes

```
w 0 f i=1:1 {w ",",i,",",-i}

```

# Answer
> 1 votes
# Reticular, 12 bytes

```
0dp1+dpd0#2j

```

Try it online!

## Explanation

```
0dp1+dpd0#2j   ; stack
0              ; [0]
 dp            ; [0]   PRINTED 0
   1+          ; [1]
     dp        ; [1]   PRINTED 1
       d0#     ; [1, -1]
          2j   ; skip two spaces after the j, wrapping to..
  p            ; [1]   PRINTED -1
   1+          ; [2]
     dp        ; [2]   PRINTED 2
       d0#     ; [2]   PRINTED -2
               ; etc.

```

# Answer
> 1 votes
## Pyth , 7 bytes

`0.V1_bb`

Explanation

```
0       # print 0
 .V1    # increment 'b' forever, starting on 1
    _b  # print -b
      b # print b

```

# Answer
> 1 votes
## MATLAB 65 bytes

My earlier post was faulty because the loop does not stop. A better try is this:

```
a=intmin('int64');(a:-a)'

```

but while this will work for the smaller int8 type it will not for int64 as the maximum array size will (of course) be exceeded. Note that transposing the vector prevents the console output from being interrupted by 'columns m to n' messages.

Another funny with MATLAB is that integers do NOT roll over, thus intmax('int64') + 1 == intmax('int64') not intmin('int64') as I expected. Also, MATLAB does not have a 'do' loop, So the best I can think of is this:

```
a=intmin('int64');b=-a;while(1) a, if a==b break, end; a=a+1; end

```

an then only if we allow the 'any separator' to allow this:

```
a =
   -9223372036854775808
a =
   -9223372036854775807
...
a =
    9223372036854775806
a =
    9223372036854775807

```

There must be a better way!

# Answer
> 1 votes
# Brain-Flak, 28 + 3 = 31 bytes

To get a program that outputs every integer in some finite time (but the whole thing in infinite time) you need to use debug flags.

Try it online

```
(@dv()@dv){([[{}]@dv]()@dv)}

```

The program is 28 bytes and the command line flag is 3 making the total 31.

An alternative that does not technically fit the specs:

Try it online

```
(({})()){([([({})])]())}

```

If you run the program you will notice there is no output. This is because Brain-flak programs output when they terminate. It will output all the numbers at once once infinite time has elapsed. If you want to verify that it works try it online with debug flags.

# Answer
> 1 votes
# Perl 6, 22 bytes

```
loop {say $--;say ++$}

```

## Explanation:

```
loop {
  say   (state $ = 0)--; # prints ｢0␤｣ first time around, then ｢-1␤｣ ｢-2␤｣ etc
  say ++(state $ = 0)    # prints ｢1␤｣ first time around, then ｢2␤｣ ｢3␤｣ etc
}

```

# Answer
> 1 votes
# C, ~~64~~ 58 Bytes

Thanks to @12431234123412341234123

```
f(n){printf(",%d,-%d",n,n);f(++n);}main(){f(printf("0"));}

```

Try it online!

A full program that terminates after printing all the integers it can represent.

Output

```
0,1,-1,2,-2,3,-3,4,-4,5,-5,6,-6,7,-7,8,-8,9,-9,10,...

```

# Answer
> 1 votes
# C, ~~51~~ 50 bytes

```
void f(){long i=0;for(;;)printf("%d %d ",i++,-i);}

```

I could save a byte by doing int instead of long, but since this can go longer than int without wrapping I'm leaving it.

Output:

```
0 -1 1 -2 2 -3 3 -4 4 -5 5 -6 6 ...

```

# Answer
> 1 votes
# bash, 46 Bytes

```
echo 0;for((i=1;;i++)){ echo -e "$i\n-$i"; }

```

# Answer
> 1 votes
## Commodore Basic, 18 bytes

```
1N=N+1:?N,1-N,:G┌1

```

PETSCII substitution:  = `SHIFT+O`

Prints the sequence "1, 0, 2, -1, 3, -2...", with characters separated by tabs.

* Work up to the numbers with the biggest magnitude of the standard integer type? Yes. Commodore Basic integers have a range of -32768 to +32767; this program uses 40-bit floats with a 32-bit mantissa, and can print any number between -999999999 and 999999999.
* Output in decimal? Yes. Integers stored in a floating-point number are printed as integers as long as they are nine digits or less.
* Each integer separated from the next using any separator? Yes. There is always a tab character between two integers.
* The separator must not change? Yes. The separator is always exactly one tab character.
* The separator can consist of multiple characters, as long as none of them is a digit nor the negative sign? Yes. A tab character is neither a digit nor a negative sign.
* Any supported integer must eventually be printed after a finite amount of time? Yes. After about 25 minutes, it'll print the sequence `32767 -32766 32768 -32767 32769 -32768`, finishing out the set of Commodore Basic-supported integers.

# Answer
> 1 votes
# dc, 16 bytes

```
zpc[zp0r-prdx]dx

```

Explanation:

```
zp    # Push stack depth (0) and peek (print top of stack and newline without popping)
c     # Clear stack
[     # Open macro definition
 z    #  Push stack depth (1 on first iteration, because this macro is on the stack)
 p    #  Peek (print positive number)
 0r-  #  Subtract ToS from 0 (make negative)
 p    #  Peek (print negative number)
 rdx  #  Rotate (move this macro on top of the negative number), duplicate, and execute
]dx   # Duplicate string and execute as macro

```

This does feel a little too similar to yeti's answer; however, this solution makes use of all-natural, grass-fed, free-range negative numbers!

In case anyone finds these to be of interest, here are some other approaches I tried:

```
zp[zp_1/plax]dsax    # uses a named macro rather than a stack-squatting macro
zpc[zdp;ar-prdx]dx   # uses an array to fetch a 0 for subtracting from...in retrospect this
                     #  is just a longer way of writing `0' and has no advantages whatsoever

0p[z1-p_1~+prdx]dx   # uses ~ with -1 to convert a positive to a negative
0p[zp_1~+plax]dsax   # uses ~ with _1 in a named macro
                   #  The difference between the two above is in stack depth: Since the
                   #  named macro doesn't reside perpetually on the stack, we don't lose
                   #  access to a number through `z'. Because the first macro must stay on
                   #  the stack, we have to decrement (`1-') to start with 1 and -1. (Both
                   #  methods require explicitly printing 0 so that it's only printed once.)

0p[zp0r-pzz>a]dsax   # uses an always-true conditional, which is also kind of pointless
0p[zp_1*ddp=a]dsax   # `_1*' == `0r-';  `ddp=a' == `pzz>a'; just some alternative notations
z[p1+_1/p_1/lax]dsax # I don't remember what I was doing with these last two
[zpd_1/+z-p0d=a]dsax #

```

Even though these other methods are all longer, I think at least half the fun is in discovering new mechanisms that one could adapt for use in other situations.

# Answer
> 1 votes
## Racket 56 bytes

(saved 12 bytes with suggestion by @StevenH)

```
(λ()(let l((i 0))(printf"~a, ~a, "i(- -1 i))(l(+ 1 i))))

```

Ungolfed:

```
(define(f)
  (let loop ((i 0))
     (printf "~a, ~a, "  i  (- -1 i))
     (loop (add1 i))))

```

Following can also be used:

```
(for((i(in-naturals)))(printf"~a, ~a, "i(- -1 i)))

```

or:

```
(for ((i (in-naturals)))
   (printf "~a, ~a, " i (- -1 i)))

```

Testing:

```
(f)

0, -1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8, -9, 9, -10, 10, -11, 11, -12, 12, -13, 13, -14, 14, -15, 15, -16, 16, -17, 17, -18, 18, -19, 19, -20, 20, -21, 21, -22, 22, -23, 23

```

# Answer
> 1 votes
**C++, 84 Bytes**

```
#include <iostream>
int main(){for(int i=0;;)std::cout<<i++<<','<<-i<<',';return 0;}

```

Edit: thanks for the debugging, commenters

# Answer
> 1 votes
# Haxe, 46 bytes

```
function f(){var i=0;while(0<1)trace(i++,-i);}

```

# Answer
> 1 votes
# RProgN, ~~22~~ 21 Bytes

```
►0p11¿]p]0\-p1+]}

```

Note the trailing space *IS* required.

Saved a byte by replacing the -1 * n with a simple 0 - n, because defining -1 in ► form takes too many bytes.

## Explination

```
►           # Read this word as a single-character based command.
0p          # Print the number 0
11          # Push two 1's to the stack.
¿           # While the top of the stack is truthy, pop the top of the stack.
    ]       # Clone the top of the stack, containing i.
    p       # Print it.
    ]       # Clone it again.
    0 \ - * # Push 0 to the stack, swap the 0 and the object underneith it, giving 0, n instead of n, 0. Subtract giving -n.
    p       # Print it.
    1+      # Add one to i
    ]       # Clone it for the next truthy check
}           # End the while statement
            # Required to interpret the while loop correctly.

```

## Output

```
0
1
-1
2
-2
3
-3
4
-4
5
...

```

This language looks nothing like it's former self. ;(

# Answer
> 1 votes
# ForceLang, ~~87~~ ~~67~~ 59 bytes

```
def w io.writeln
w 0
label a
w set i 1+i
w i.mult -1
goto a

```

# Answer
> 1 votes
# C, 44 bytes

```
long l;f(){printf("%ld ",l);l=(l<=0)-l;f();}

```

Note that the (implicit) `int` return type does not cause `f` to require a `return` because `f` never reaches the end of the function.

This code uses the fact that globally defined variables are initialized to zero.

Note that on a system with unlimited memory (or with a compiler that does tail recursion elimination)there will be no stack overflow, therefore this program fulfils the requirements.

# Answer
> 1 votes
# Java 8, 87 bytes

Alternative solution using an IntStream to iterate through all integers.

```
java.util.stream.IntStream.rangeClosed(1<<31,~1<<31).forEach(n->System.out.println(n));

```

## Alternative, 57 bytes

I didn't want to post this as my main answer, because it's just stolen from @KevinCruijssen's Java 7 answer, switched to go from negative to positive for no particular reason, and turned into a lambda. But it is technically shorter.

```
()->for(int i=1<<31;i<0;System.out.println(i+"\n"+~i++));

```

# Answer
> 1 votes
# Excel VBA, ~~25~~ 20 Bytes

Anonymous VBE immediate window function that takes no input and outputs to the vbe immediate window

```
Do:?1-n;n:n=n+1:Loop

```

*Note: Excel will appear to be non-responsive after executing to n=6012, adding a `DoEvents:` call at the beginning of any of the lines in the `do`...`loop` corrects this visual bug, but is not necessary for correct execution.*

# Answer
> 1 votes
# JS (**NON - ES6**), 25 bytes

```
for(n=0;;)alert([~n,n++])

```

Uses binary NOT (`~`) for reverse sign and deincrement.

# Answer
> 1 votes
# Implicit, ~~6~~ ~~5~~ 4 bytes on TIO

```
(%.ß

```

Requires that the input box on TIO be empty.

```
(...    « do..while top of stack truthy                 »;
 %      «  print top of stack as int                    »;
  .     «  increment (reads from input if stack empty)  »;
   ß    «  print space                                  »;
    ¶   « (implicit) just kidding, loop forever         »;

```

Try it online!

# Implicit, 5 bytes

```
0(%.ß
0        « push 0           »;
 (%.ß    « (same as above)  »;

```

# Answer
> 1 votes
# Aceto, 9 bytes

```
dpnd~pnIO

```

```
d duplicates the top val
p prints it
n does a newline
~ negates  the top val
I Increments the top val
O returns to the beginning of the program
```

Try it online!

# Answer
> 1 votes
# Common Lisp, 42 bytes

```
(do((i 0))(())(print(- i))(print(incf i)))

```

Try it online!

# Answer
> 1 votes
# Momema, 26 bytes

```
z0-8*0-9 00+1*0-8-*0-9 0z1

```

Try it online!

This outputs null bytes as the separator (though TIO displays them as spaces).

Alternatively, at a cost of 1 byte, here's a version that uses tabs instead of null bytes:

```
z0-8*0-9 9 0+1*0-8-*0-9 9z1

```

## Explanation

```
                                                   #  a = 0
z   0     #  label z0: jump past label z0 (no-op)  #  while true {
-8  *0    #            output number [0]           #    print a
-9  0     #            output chr 0                #    print '\0'
0   +1*0  #            [0] = [0] + 1               #    a++
-8  -*0   #            output number -[0]          #    print -a
-9  0     #            output chr 0                #    print '\0'
z   1     #  label z1: jump past label z1          #  }

```

# Answer
> 1 votes
# Forked, 21 bytes

```
%A!v
   >1+%A!AF*!%A!

```

First, this does `%A!` (print 0 followed by a newline), then executes the code in my original answer below, before I realized we were supposed to print 0 too:

---

# Forked, 12 bytes

```
1+%A!AF*!%A!

```

Try it online!

* `1+` \- add 1 to the top of the stack
* `%` \- print top of stack as integer
* `A!` \- print 0xA (ASCII newline)
* `AF*!` \- print 0xA × 0xF = 0x2D (ASCII `-`)
* `%` \- print top of stack as integer
* `A!` \- print 0xA (ASCII newline)

Forked is two-dimensional, so the IP wraps upon hitting the edge of the playing field.

This just loops through every integer, prints it followed by a newline, then prints it again, preceded by a `-` and proceeded by a newline.

# Answer
> 1 votes
# Appleseed, 41 bytes

```
(def I(q(((n 0))(cons n(I(sub(less? n 1)n

```

Defines a function `I` that takes no arguments and returns an infinite list of integers, starting `(0 1 -1 2 -2 ...)`. Try it online!

Note: Appleseed is in the early stages of development at the moment, so if this code stops working at some point in the future, ping me and I'll update it.

### Ungolfed + explanation

```
; Load the library for functions & macros such as lambda
(load library)
; Define all-integers to be...
(def all-integers
  ; a lambda function with one optional argument, n, whose default value is 0
  (lambda ((n 0))
    ; The function prepends n to...
    (cons n
      ; the result of a recursive call...
      (all-integers
        ; whose argument is (n<1) - n, i.e. -n if n is positive, else -n+1
        (sub (less? n 1) n)))))

```

# Answer
> 1 votes
# Pyt, 11 bytes

```
00Ƥ`⁺ĐĐ~ƤƤł

```

Try it online!

```
00   pushes 0 twice
Ƥ    prints with a newline separator
`    indicator for looping
⁺    increments
ĐĐ   duplicates twice
~    negates top value
ƤƤ   prints positive and negative value
ł    loops till top is zero (never)

```

# Answer
> 1 votes
# Coconut, 25 bytes

```
def f(n=0)=[n,~n]::f(n+1)

```

Try it online!

# Answer
> 1 votes
# Milky Way, 9 bytes

```
&{!k1-!j}

```

Try it online!

## How?

```
           initial Stack: ["", 0]
&{      }  infinite loop
  !        output ToS
   k       negative absolute value
    1-     subtract 1
      !    output ToS
       j   absolute value

```

# Answer
> 1 votes
# Yabasic, 22 bytes

An anonymous answer that takes no input and outputs all integers to the console.

```
?0
Do
i=i+1
?-i,i
Loop

```

Try it online!

# Answer
> 1 votes
# QBasic, 23 bytes

Script that takes no input and outputs to the console. Values are newline delimited and increment in the order of \\$0, -1, 1, -2, 2, \cdots\\$.

```
?0
Do
i=i+1
?-i
?i
Loop

```

# Answer
> 1 votes
## Python 3, 44 bytes

```
i=0;print(i)
while 1:i+=1;print(i);print(-i)

```

Try it online!

# Answer
> 1 votes
# Keg, `-pn`, ~~15~~ 9 bytes

```
0.1{:④±.⑨

```

Try it online!

## Answer History

### 15 bytes

```
0. ,1{④± ,④ ,±⑨

```

Try it online!

Really messy I know, but it works. Integers are space seperated

# Answer
> 1 votes
# C, 55 Bytes

`i=1;f(){putc('0');while(i>0){printf(",%d,%d",-i,i++);}}`

## Explanation

```
/*int*/ i = 1;
int f()
{
    putc('0');/*Print out 0 because -0 isn't a number*/
    while(i>0) /*i>0 handles overflow, ensuring all valid *
                 * integers are printed once and only once  */ {
        printf(",%d,%d",-i,i++);
        /* Unpacking the above line:
        the 1st %d prints out -i
        the 2nd %d prints out i
        i++ adds 1 to i(after it's passed to the printf)*/
    }
}

```

I put the comma at the beginning of the printf statement so that I didn't have to put it at the end of the puts and at the end of the printf.

Output: `0,-1,1,-2,2...`

## Edit: full C program version

@cleblanc made an answer that is a full C program, rather than a function, so I decided to do that too(Our answers are otherwise completely separate).

# C, 58 Bytes

`i=1;main(){putc('0');while(i>0){printf(",%d,%d",-i,i++);}}`

## Explanation

More or less the same as the original answer, but changing the function's name to `main` makes it a standalone program, rather than a function.

# Answer
> 1 votes
# cQuents, 7 bytes

```
=0:k,-k

```

Try it online!

Do you really need an explanation?

# Answer
> 1 votes
# Red, 37 bytes

```
n: 1 forever[print[n 0 - n]n: n + 1]0

```

# Answer
> 1 votes
# Symja, ~~38~~ 37 bytes

```
i=0;While(0<1,Print(i);i++;Print(-i))

```

Try It Online!

To see that this will work for all integers, view this demonstration for numbers up to 100.

# Answer
> 1 votes
# Julia, 24 bytes

```
f(n=0)=f(~n+(0>@show n))

```

Try it online!

# Answer
> 1 votes
# BRASCA, ~~20~~ 18 bytes

-2 bytes thanks to RezNesX

```
nEo1[:nEo:0$-nEo}]

```

Try it online!

## Explanation (old)

```
<implicit>           - The stack has infinite zeroes at the bottom
nEo                  - Print "0" and a space
   1[a            A] - Infinite loop:
      }:nEo          -   Print next positive integer and a space
           $         -   Swap to the negative number on the stack
            {:nEo    -   Print next negative integer and a space
                 $   -   Swap back to the positive number on the stack

```

# Answer
> 1 votes
# Vyxal `5`, 8 bytes

```
∞›(n,n⌐,

```

**Explanation:**

```
∞›(n,n⌐, # main program
∞›       # creates an infinite generator starting at 1
  (      # iterates over it
   n,    # prints the numbers [1, ∞)
     n⌐, # prints the numbers (-∞, 0]

```

Mapping would be better, but currently mapping generator output is not optimal.

Try it Online!

# Answer
> 1 votes
# AWK, ~~33~~ 32 bytes

This code prints all integers in one line:

```
BEGIN{for(ORS=FS;;)print -i++,i}

```

An alternative 33-byte answer, which prints one integer per line:

```
BEGIN{for(;;)print n+=i++*(-1)^i}

```

Try it online!

# Answer
> 1 votes
# GolfScript, 12 bytes

```
0{.p.~p).}do

0            # push 0 to the stack
 {           # this block will execute at least once, even though the TOS is 0
  .p         # print the current number
    .~p      # print the bitwise NOT of the current number
       )     # increments the current number
        .}do # creates an infinite loop

```

Because the bitwise NOT of x = (-x - 1), as the number increments, the inverse decrements. The bitwise NOT of 0 is -1, therefore it can be trivially proven that all integers are counted exactly once.

I know there's already a (longer) GolfScript solution here, I apologise if this is breaking any rules.

# Answer
> 1 votes
# Kotlin, ~~49~~ 48 bytes

```
(Int.MIN_VALUE..Int.MAX_VALUE).onEach(::println)

```

Saved one byte by using another iterator function

Try it online!

#### 49 bytes variant

```
(Int.MIN_VALUE..Int.MAX_VALUE).forEach(::println)

```

Try it online!

Expected output

```
-2147483648
-2147483647
-2147483646
...
-1
0
1
2
...
2147483645
2147483646
2147483647

```

The program will take a while since this is only a single threaded printing and integer values reach -2147483648 to 2147483647.

# Answer
> 1 votes
# Commodore C64 BASIC, 29 BASIC Bytes (does not end gracefully), 24 PETSCII characters with keyword abbreviations

```
0?i%,nO(i%),;:i%=i%+1:gO

```

By declaring a variable with a `%` identifier, you are telling Commodore BASIC to produce only integer representations of any floating point number, and this is within the range of -32768 to +32767 inclusive. The `nO` command, or `NOT` is a bitwise operator which may only be used with the same range previously mentioned (`PRINT NOT (32768)` for instance produces an `?ILLEGAL QUANTITY ERROR`. Further reading about this is detailed here.

Because we are using line 0, we don't need to specify a line number with the `GOTO` command (at least not in BASIC 2.0 on the C64 and VIC-20; this may not be the same for all versions of Commodore BASIC).

The output is produced like:

`0 -1 1 -2`

and will continue until the maximum range is met, and produce an error.

## With a graceful ending, 39 BASIC Bytes, 35 PETSCII characters with keyword abbreviations

```
0?i%,nO(i%),;:i%=i%+1:ifi%<32768then0

```

The same as above, but an `IF` condition is added. We can just use `THEN0` rather than `THEN GOTO 0` to save some typing.

# Answer
> 1 votes
# Fortran (GFortran), 34 bytes

```
i=0
1 i=i+1;print*,1-i,i;goto1;end

```

Boringly had to waste 4 bytes setting `i=0` otherwise Fortran just initialises the variable to anything

Try it online!

# Answer
> 1 votes
# Uiua, 18 bytes

```
⍥(+⟜⊃±∵&s)∞¯1_1&s0

```

Explanation:

```
  ⍥(+⟜⊃±∵&s)∞¯1_1&s0
# ^ ^ ^^^   ^^   ^
# | | |||   ||   └- print 0
# | | |||   |└----- [-1 1]
# | | |||   └------ do infinitely
# | | ||└---------- print each
# | | |└----------- sign of elements
# | | └------------ fork both functions
# | └-------------- increment by sign
# └---------------- repeat until

```

# Answer
> 1 votes
# Swift 5.9, 32 bytes

```
(0...).map{print($0)
print(~$0)}

```

I tried *desperately* to merge the two calls to `print(_:separator:terminator:)` into one, but the fact that `terminator` is a newline by default seriously complicates things.

# Answer
> 0 votes
# Non-wrapping Brain\****, 9 bytes

Thanks to Scepheo for saving one byte!

```
+[.+<.->]

```

# Answer
> 0 votes
## Bash, ~~33~~ 55 bytes

```
for((;;)){ echo -n $[-i++],$i,;((i==LLONG_MAX))&&exit;}

```

Unfortunately bash won't give an integer overflow error when `$i` exceeds the maximum size of the type used to store it. Therefore, I updated the code to include a termination criteria, that requires `$LLONG_MAX` to be defined in the environment or passed on the command line.

**Run example:** on my system bash uses signed 64-bit integers

```
LLONG_MAX=$[2**63-1] ./all_integers.sh

```

The following code is a 32 byte version (1 less) of my original post, that assumed undefined printing behavior after the integer overflow.

```
for((;;)){ echo -n $[-i++],$i,;}

```

# Answer
> 0 votes
# Oracle SQL 11.2, ~~77~~ ~~73~~ ~~72~~ 68 bytes

```
SELECT CEIL((LEVEL-1)/2)*(MOD(LEVEL,2)*2-1)FROM DUAL CONNECT BY 1=1;

```

# Answer
> 0 votes
# C++ with Boost, 143 bytes

```
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
boost::multiprecision::cpp_int i;main(){while(++i)std::cout<<1-i<<','<<i<<',';}

```

Not very short, but it does use an arbitrary-precision type. To test that, I tried replacing ++i with i=2\*i+1, and very soon there were numbers several hundred digits long being printed correctly. This should work until the number takes up all your stack memory.

# Answer
> 0 votes
# Swift 3 (34 bytes)

```
(Int.min...Int.max).map{print($0)}

```

Really, we should be able to get this down to 30 bytes like so:

```
(Int.min...Int.max).map(print)

```

But the compiler doesn't allow this yet.

# Answer
> 0 votes
# k (20 bytes)

The function between curly braces is repeatedly iterated on it's result, starting at zero, until the result converges at `0W` (k infinity).

```
{-1@'$?-1 1*x;x+1}/0

```

The function prints the argument and its negation and then returns incremented argument.

# Answer
> 0 votes
# Python, 40 bytes

```
p=print
p(0)
i=1
while 1:p(i);p(-i);i+=1

```

# Answer
> 0 votes
# C# function 53 bytes

```
int j;void X(){for(;;)Console.Write($"{j++},-{j},");}

```

Explanation:

Create a variable "j" in class scope. This will default to have a value of zero. Write and increment value and then write the negative of that value. This will output "0,-1," on the first loop and "1,-2," on the 2nd loop.

# Answer
> 0 votes
## QBIC, 14 bytes

```
{?1-q ?q q=q+1

```

`q`is 1 by default in QBIC, so this prints (1-1=) 0, 1, -1, 2, -2... separated by line breaks.

# Answer
> 0 votes
## Straw, 26 bytes

```
~(~$:>(,-)>:>(,)>#0+~:&):&

```

Try it online!

```
~(~$:>(,-)>:>(,)>#0+~:&):&
~ ~                 ~      Swap between the two stacks
 (                     )   Push a string literal
   $                       Unary -> decimal
    :      :         :     Duplicate
     >    > >   >          Output
      (,-)   (,)           String literal
                 #         Decimal -> unary
                  0        Push the character '0'
                   +       Concatenate
                      &  & Evaluate

```

It prints `-0` too, not sure if it's allowed though

# Answer
> 0 votes
# Pushy, 7 bytes

```
0[~#|h#

```

**Try it online!** (will eventually cut the output)

Explanation:

```
0     \ Push 0 as the starting counter
[     \ Infinitely:
 ~#   \   Negate counter (and print)
 |h   \   Push abs(counter)+1
 #    \   Print counter

```

This prints in the pattern `0 1 -1 2 -2 3 -3...`, separated by newlines.

Pushy's reference implementation is in Python, which uses arbitrarily sized integers, and so there won't be any overflow if you run this for a *long* time. However, the integer would eventually get too large and cause a `MemoryError`.

# Answer
> 0 votes
# CJam, 10 bytes

```
0{_n~_nz}h

```

Try it online!

# Answer
> 0 votes
# Triangular, 21 bytes

```
()ip.%@,|<.>A@\/A|%p<

```

(Does not work on the TIO version yet.) Formats into this triangle:

```
     (
    ) i
   p . %
  @ , | <
 . > A @ \
/ A | % p <

```

This got really messy once I realized there had to be delimiters between the numbers.

The directionals (`<,>\/`) poke the IP around to get this code executed:

```
(i%|A@p%|A@p)

```

How it works:

* `(` opens a loop.
* `i` increments the top of stack.
* `%` prints the top of stack as an integer.
* `|` negates the top of stack.
* `A` pushes 10 to the stack.
* `@` prints the top of stack as ASCII `\n`.
* `p` pops the 10. Now the top of stack is the negated value.
* `%` prints the top of stack (negated value).
* `|` un-negates the top of stack.
* `A` pushes 10 to the stack again.
* `@` prints as ASCII `\n`.
* `p` pops the top of stack.
* `)` unconditionally jumps back to the loop.

# Answer
> 0 votes
# uBASIC, 24 bytes

An anonymous answer that takes no input and outputs to the console.

```
0?0
1i=i+1:?i,0-i:GoTo1:

```

Try it online! (and yes, the terminal `:` is necessary)

# Answer
> 0 votes
# MY-BASIC, 38 bytes

```
Print 0;
While 1
i=i+1
Print-i;i;
Wend

```

Try it online!

# Answer
> 0 votes
# Visual Basic .NET (Mono), 95 bytes

A declared subroutine that takes no input and outputs to the console.

```
Module M
Sub Main
Dim i
Do
Console.WriteLine(-i &IIf(i," "&i,""))
i=i+1
Loop
End Sub
End Module

```

Try it online!

# Answer
> 0 votes
# F#, 69 bytes

```
let f=
 let mutable i=0m
 while 1>0 do
  printf"%O,-%O,"i i
  i<-i+1m

```

It's pretty straight forward. The `0m` sets `i` as 0, but of type `decimal`. Since we're allowed to print `0, -0` I'm doing that. `i` gets incremented with every iteration of the loop, and the value is printed out.

I my initial idea would have been **70 bytes** but (like most of my initial ideas) it would never have worked:

```
let g=Seq.iter(fun x->printfn"%O,-%O"x x)[0m..System.Decimal.MaxValue]

```

In this one `[0m..System.Decimal.MaxValue]` creates an array starting at 0, adding 1 each time and going all the way to the maximum `decimal` value. (Another example would be the expression `[1..10]` creates an array with {1,2,3,4,5,6,7,8,9,10}).

`Seq.iter` would then apply the function for printing to that array.

The problem with this is that the array must be constructed before iterating through it. So for all integers, with infinite memory the array could be constructed - but it would also take an infinite amount of time, so nothing would ever be printed out!

# Answer
> 0 votes
# Japt, ~~12~~ 10 bytes

```
_OlU°,Un}a

```

Try it online!

## Explanation:

```
_OlU°,Un}a
            | Implicit U = 0
_       }a  | Start an infinite loop
 Ol         | Write to the console:
   U°       |   U++
     ,      |    and
      Un    |   0-U

```

# Answer
> 0 votes
# Javascript, 96 bytes

```
f=n=>f([].concat(...n.map(i=>alert(+i?i+' -'+i:i)||+i?y.map(o=>i+o):[])));f(y=[...`0123456789`])

```

Alerts all integers in the sequence (0, 1, -1, 2, -2, ...), using strings to go beyond JS's usual max safe integer 9007199254740991. This is equivalent to the "Infinite version" in Arnauld's earlier answer.

# Answer
> 0 votes
# Scala, 112 bytes

```
val x=Int.MaxValue
val y=Int.MinValue
print(0)
for(a <-1 until x) print(","+a + "," + a * -1)
print(","+x+","+y)

```

Try it online!

# Testable Running Program with limits \[-10,10\]

# Scala, 143 bytes

```
object ListNumbers extends App {
  val x = 10
  val y = -10
  print(0)
  for(a <- 1 until x) print(","+a + "," + a * -1)
  print(","+x+","+y)
}

```

Try it online!

# Using Java 8 Streams just for fun, it generates a lazy populated string

*types declarations can be omitted but I included for "documentation"*

# Scala, 253 bytes

```
val zero :Stream[String] = Stream("0")
val positive :Stream[Int]= Stream.from(1)
val negative :Stream[Int]= positive.map(_* -1)

val stream = zero ++ positive.zip(negative).map(x => x._1.toString()+","+x._2.toString())
//stream.take(Int.MaxValue).toList

```

Try it online!

# Answer
> 0 votes
# Gol\>\<\>, 7 bytes

```
lN01l-N

```

Try it online!

### How it works

```
lN01l-N
l        push current stack length (n)
 N       pop and print with newline
  01l    push 0, 1, then stack length (n+2)
     -   pop n+2, 1, then push 1 - (n+2) = -n-1
      N  pop and print with newline
         now the stack length is n+1; repeat indefinitely

```

# Answer
> 0 votes
# Zephyr, 48 bytes

```
set i to 0
while 1=1
print-i,i+1...
inc i
repeat

```

Space-separated. If the separator could alternate between space and newline, the `...` could be removed for -3 bytes. Try it online!

# Answer
> 0 votes
# Small Basic, 92 bytes

A Script that takes no input and outputs to the `TextWindow` object.

```
TextWindow.Write(0+" ")
While 1=1
i=i+1
TextWindow.Write(Text.Append(-i+" ",i+" "))
EndWhile

```

# Answer
> 0 votes
# Jellyfish, 19 bytes

```
\~-0
0~p
 ~-
 ~>
 p

```

Try it online!

A (Sort-of) port of Dennis' Jelly solution.

## Explanation

(`~` is function composition)

```
\    iterate the following function
0    on 0
   0 till 0 occurs:
 ~-  negate the result of
 ~p  printing
 ~-  the negation of
 ~>  addition of 1 to
 p   printing the argument.

```

# Answer
> 0 votes
# Pure yash and `echo` (or POSIX-compatible shell), 42 bytes

Separator is space or LF.

```
while echo ${#a} ${a+-${#a}};do a=.$a;done

```

## How it works

* `${#a}` is length of string contained in the variable.
* `${a+xxx}` is content of variable a, if a is null string; otherwise string xxx.
* Undefined variable is expanded to null string.

Try it online!

# Answer
> 0 votes
# JavaScript (Node.js), 38 bytes

```
for(n=-1;++n!=NaN;){console.log(n,-n)}

```

Try it online!

# Answer
> 0 votes
**TurboBasic XL (Atari 800XL), 21 Bytes**

`DO:I=I+1:?1-I,I,:LOOP`

Output is: 0 1 -1 2 -2 3 -3 4 ...

**Buildin Basic (Atari 800XL), 18 Bytes**

`0I=I+1:?1-I,I,:G.0`

# Answer
> 0 votes
## Pascal, N/A

Pascal enforces good programming style. Pascal forces you to ignore the fact that your code will (eventually) run on a computer with technical limitations. This is a consistent design choice. You – the programmer – are supposed to focus on the algorithm.

The “native integer type” in Pascal is called `integer`. However, you *cannot* inspect *from* your *Pascal source code* its implementation characteristics. The built‑in *implementation‐defined* constant `maxInt` is associated with *minimum* requirements. Technically it is possible and not forbidden that `integer` can store even more integer values.

```
program z(output);var n:integer;begin for n:=-maxInt to maxInt do writeLn(n)end.
program z(output);var n:integer;begin n:=maxInt;for n:=-n to n do writeLn(n)end.

```

If your processor supports Extended Pascal (ISO standard 10206), you can also use a set‑membership‐iteration statement. Note the specific order values are printed is *implementation‐dependent*.

```
program z(output);var n:integer;begin n:=maxInt;for n in[-n..n]do writeLn(n)end.

```

If the *implementation‐defined* value of the default minimum printing width is at least \\$\lfloor \log\_{10}\text{maxInt}\rfloor + 3\\$ (`+3` to accommodate a sign and at least one intervening space), you can drop the `Ln`:

```
program z(output);var n:integer;begin for n:=−maxInt to maxInt do write(n)end.

```

---
Tags: code-golf, number, integer, open-ended-function
---