[Question]
  [
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
 
 
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/104323/edit).
Closed 2 years ago.
[Improve this question](/posts/104323/edit) 
Your task is to write a full program or function that takes no input and runs any type of loop (`while`, `for`, `foreach`, `do`, `do-while`, `do-loop`, `goto`, recursion, etc) that will end in causing an error, which means that the program must stop itself running and exit.
**Rules:**
1. The error must be a run-time error, unhandled exception, or anything that makes the program end itself.
2. The error must produce the stop and exit from the program without calling explicitly `exit;` (or equivalent) at some point.
3. Messages like `Warning:`, `Notice:`, etc, that do not cause the program to end itself are not valid. For example in PHP divisions by zero produces a `Warning` message but the program will not stop and will still run, this is not a valid answer.
4. The loop must run at least one full cycle. In other words the error can happen starting at the second cycle and further. This is to avoid to cause the error using incorrect code syntax: the code must be syntactically correct.
5. The loop can be even infinite (example `for(;;);`) if it respects the above said rules, but must take no longer than 2 minutes to end itself in a run-time error.
6. Recursion without Tail Call Optimization is invalid ([1](https://stackoverflow.com/a/33930/2096343),[2](https://stackoverflow.com/a/310980/2096343)).
7. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest code wins.
8. [Standard loopholes](http://meta.codegolf.stackexchange.com/q/1061/59718) are forbidden.
**C# example ([test online](https://dotnetfiddle.net/oIM5Ds)):**
```
using System;
public class Program {
    public static void Main() {
        int i;
        int[] n;
        n = new int[5];
        for(i=0; i<7; i++) {
            n[i] = i;
            Console.WriteLine(n[i]);
        }
    }
}
Output: 
0
1
2
3
4
Run-time exception (line 9): Index was outside the bounds of the array.
Stack Trace:
[System.IndexOutOfRangeException: Index was outside the bounds of the array.]
  at Program.Main(): line 9
```
**Leaderboard:**
```
var QUESTION_ID=104323,OVERRIDE_USER=59718;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;font-family:Arial,Helvetica; font-size:12px}#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>
```
Thanks to [Martin Ender](https://codegolf.stackexchange.com/users/8478/martin-ender) for the [Leaderboard Snippet](http://meta.codegolf.stackexchange.com/questions/5139/leaderboard-snippet)
  
[Answer]
# Python, 16 bytes
The non-interesting 0 division approach:
```
for x in 1,0:x/x
```
The first iteration computes `1 / 1`, which works fine. The second iteration tries to compute `0 / 0`, resulting in a `ZeroDivisionError` being thrown.
## 17 bytes (personal favourite)
```
i=1
while i:del i
```
Initially, `i=1` which is truthy, so the loop is entered.
The first time the loop is run, the variable `i` is deleted.
This means that, the second time, `i` is no longer a variable and therefore its evaluation fails with `NameError: name 'i' is not defined.`
---
Another 15 byte solution would be `def _():_()` (newline) `_()`, because Python does not optimize tail recursion. However, this violates rule #6.
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~5~~ 1 byte
*Idea taken from @MartinEnder's [CJam answer](https://codegolf.stackexchange.com/a/104330/36398)*
```
`
```
[Try it online!](https://tio.run/nexus/matl#@5/w/z8A)
```
`    % Do...while loop
     % Implicit end. The loop continues if the top of the stack is true.
     % After the first iteration, since the stack is empty, the program 
     % implicitly tries to take some non-existing input, and finishes
     % with an error
```
---
### Old version
```
2:t"x
```
[Try it online!](https://tio.run/nexus/matl#@29kVaJU8f8/AA "MATL – TIO Nexus")
```
2:   % Push [1 2]
t    % Duplicate
"    % For each (i.e. do the following twice)
  x  %   Delete top of the stack. Works the first time. The second it tries to
     %   implicitly take some non-existing input, and finishes with an error
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~3~~ 2 bytes
```
Ṿß
```
Kills itself by running out of memory. Locally does so after ~100 seconds.
[Try it online!](https://tio.run/nexus/jelly#@/9w577D8///BwA "Jelly – TIO Nexus") (death certificate in *Debug* drawer)
### How it works
```
Ṿß  Main link. Argument: x. Implicit first argument: 0
Ṿ   Uneval; yield a string representation of x.
 ß  Recursively call the main link.
    Jelly uses TCO, so the first cycle finishes successfully before entering
    the next one.
```
The first few iterations yield:
```
'0'
'”0'
'””,”0'
'””,””,”,,””,”0'
'””,””,”,,””,””,”,,””,”,,”,,””,””,”,,””,”0'
'””,””,”,,””,””,”,,””,”,,”,,””,””,”,,””,””,”,,””,”,,”,,””,””,”,,””,”,,”,,””,”,,”,,””,””,”,,””,””,”,,””,”,,”,,””,””,”,,””,”0'
```
After that, it gets real ugly, real fast.
[Answer]
# [V](https://github.com/DJMcMayhem/V), 2 bytes
```
òl
```
[Try it online!](https://tio.run/nexus/v#@394U87//xmpOTn5igA "V – TIO Nexus")
This is the *perfect* challenge for V because I already do that all the time! In fact, V doesn't even have any conditionals, it only has functions that break on an error. In this case, the `ò` means "repeat forever" and the `l` means "move right". 
In an empty buffer (no input) this will break on the first pass and produce no output. If there *is* input, it will break once we move post the last character of input, and output all of the input (making this also a cat program)
[Answer]
# JavaScript (ES6), 13 bytes
```
f=_=>f(_?a:1)
```
This is a recursive function that runs fine once, then throws `ReferenceError: a is not defined` and quits.
Here's a 15-byte non-ES6 version:
```
for(i=0;;)i=i.a
```
This runs fine once, then throws `TypeError: i is undefined` and quits.
[Answer]
# [GNU sed](https://www.gnu.org/software/sed/), ~~15 13~~ 5 bytes
-2 Thanks to [seshoumara](https://codegolf.stackexchange.com/users/59010/seshoumara)  
-8 Thanks to [zeppelin](https://codegolf.stackexchange.com/users/61904/zeppelin)
```
H;G;D
```
1. Appends a newline and the hold space to the pattern space.
2. Appends a newline and the pattern space to the hold space.
3. Deletes up to the
first newline and starts over.
This quickly runs out of memory:
```
$ time (echo|sed 'H;G;D')
sed: couldn't re-allocate memory
real    0m1.580s
user    0m0.545s
sys     0m1.012s
```
[Answer]
# Bash 4.2, 22 bytes
```
exec $0 $@ $[2**$#%-1]
```
Doesn't work in TIO because it has Bash 4.3, and the bug I'm relying on was *finally* fixed.
### Verification
```
$ xxd -c 22 -g 22 self-destruct
0000000: 6578656320243020244020245b322a2a2423252d315d  exec $0 $@ $[2**$#%-1]
$ ./self-destruct
Floating point exception
```
This crashes once the program tries to compute **263 mod -1**, which crashes in Bash 4.2 and older versions due to a known bug.
[Answer]
# Befunge-93, 3 bytes (possibly 1 or 0)
```
!%!
```
[Try it online!](http://befunge.tryitonline.net/#code=ISUh&input=)
On the first iteration of the loop, the stack is empty, which is the equivalent of all zeros. The `!` (not) operation thus converts the stack top to 1, and the `%` (modulo) operation calculates 0 mod 1, leaving 0. The next `!` operation converts that 0 to a 1 before the program counter wraps around and begins the loop again.
On the second iteration, the first `!` operations converts the 1 that is now at the top of the stack to a 0. The `%` operation then calculates 0 mod 0, which produces a division by zero error on the reference interpreter, and thus terminates the program.
There's also the more boring 1 byte answer, although I'm not sure if this is considered valid.
```
"
```
[Try it online!](http://befunge.tryitonline.net/#code=Ig&input=)
This `"` command starts a string, thus every space on the rest of the line is pushed onto the stack until the program counter wraps around and encounters the `"` again closing the string. It'll then need to wrap around a second time to repeat the process starting another string and pushing another 79 spaces onto the stack. Eventually this will either run out of memory (the reference interpreter behaviour) or produce a stack overflow.
Now if you want to really push the rules there's also technically a zero byte solution.
```
```
If you take [this ruling](http://meta.codegolf.stackexchange.com/a/7833/62101) to mean that *any* interpreter defines the language (as many here do), then we can assume for the moment that the Befunge language is defined by [this interpreter](http://kermit.kishwaukeecollege.edu/~dklick/cis119/Befunge93.html). And one of the "features" of that interpreter is that it pushes an *Undefined* value onto the stack for each loop of the playfield when executing a blank program. Given enough time it will eventually run out of memory.
How fast that happens will depend on the speed of the computer, the available memory, and the browser being used. On my machine I found that Microsoft Edge worked best, but even then it was "only" using 500MB after two minutes. It wasn't until around the fifteen minute mark (with several gigabytes used) that Edge decided to kill the process and refresh the tab. So it's unlikely to make it under the two minute time limit, but with the right conditions that wouldn't necessarily be out of the question.
[Answer]
# PHP, ~~22~~ ~~21~~ ~~20~~ 18 bytes
This relies on PHP allowing one to give a function name to a variable and try to run it.
This simply concatenate the name of the `pi` function twice. This kills PHP with a `Fatal Error: Uncaught Error: Call to undefined function pipi() in [...][...]`.
```
while($x.=pi)$x();
```
This works similar to my old answer.
---
**Old answer, 20 bytes**
PHP allows you to increment characters, using the increment operator.
It only works on the `a-z` range, but is enough.
```
for($x=pi;;)$x=$x();
```
I believe this fulfills all the required points and the loop does run once.
You can see if because you will get the error `Fatal error: Function name must be a string`.
---
How this works, step by step:
* Assign `pi` to `$x`.  
Since `pi` is being used as a constant, PHP will check if exists.  
Since it doesn't, PHP shows a warning saying `Use of undefined constant pi - assumed 'pi'` (Basically: since the constant doesn't exist, it is assumed to be a string)
* Loop the first time
	+ Run the function `$x()`.  
	
	Since `$x` has the value `pi`, it will run the function `pi()`.
* Store the value in `$x`.  
`$x` now has π, instead of `pi`
* Loop for the second time
	+ Run the function `$x()`.  
	
	Since `$x` has π, it will run the function `3.14159...()`.
	+ π isn't a string, killing the program at this point with a `Fatal Error`.
---
Thanks to [@Titus](https://codegolf.stackexchange.com/users/55735/titus) for finding the `pi()` function, saving me **1** byte!
[Answer]
## C, 21 bytes
```
i;f(){for(;1/!i++;);}
```
Here `i` is guaranteed to start off as `0`.
It can be confirmed that this runs once like so:
```
i;f(){for(;1/!i++;)puts("hi");}
main(){f();}
```
Which, on my machine, results in:
```
llama@llama:...code/c/ppcg104323loop$ ./a.out 
hi
zsh: floating point exception (core dumped)  ./a.out
```
The shortest recursive solution I can find is **22 bytes**:
```
f(i){f(i-puts(""-i));}
```
`gcc` only does tail call elimination at `-O2` or higher, at which point we need to call a function like `puts` to prevent the entire thing from being optimized away. Confirmation that this works:
```
llama@llama:...code/c/ppcg104323loop$ cat loop.c       
main(){f();}
f(i){f(i-puts(""-i));}
llama@llama:...code/c/ppcg104323loop$ gcc -O2 -S loop.c 2>/dev/null
llama@llama:...code/c/ppcg104323loop$ grep call loop.s
    call    puts
    call    f
```
The following is a full program, which assumes that it is called with no command line arguments, at **22 bytes**:
```
main(i){for(;1/i--;);}
```
which is equivalent to the function of the same length:
```
f(i){for(i=1;1/i--;);}
```
[Answer]
## R, 22 25 22 20 18 bytes
Edit: Thanks to @Mego for pointing out that R does not support tail call optimization. 
Edit4: Found an even shorter solution which simple yet quite intricate.
```
repeat(ls(T<-T-1))
```
The answer uses the builtin boolean truthy variable, `T` which is decremented indefinitely in the repeating loop. The function `ls()` is called each iteration which lists all objects in the current environment. However, the first argument `name` specifies from which environment from which to list objects. From the R-documentation we find that:
> 
> The name argument can specify the environment from which object names are taken in one of several forms: as an integer (the position in the `search` list); as the character string name of an element in the search list; or as an explicit `environment` (including using `sys.frame` to access the currently active function calls). 
> 
> 
> 
This principally means that in the first iteration we run `ls(-1)` which would return `character(0)` (standard when trying to access the non-existent `everything-except-the-first` element of any character type object). During the second iteration, `T` is decremented by two and we subsequently call `ls(-3)` which in turn returns the error:
```
Error in as.environment(pos) : invalid 'pos' argument
```
This is because we try to list `everything-except-the-third` element but the local environment only contains the variable `T` at this point (as such, `ls()` would return a list of length `1` at this iteration) and an error is returned.
[Answer]
# FALSE, 8 bytes
I really like this language.
```
1[$][.]#
```
This pushes a `1`, then `[$][.]#` loops while `$` is true (duplicate top of stack) and (`.`) outputs it. [This interpreter](http://morphett.info/false/false.html) crashes after the single `1` is printed (evidence of the loop running at least once.) It seems to be a bug in this interpreter. The following 9-byte program should work in all compliant interpreters:
```
1[$][..]#
```
[Answer]
# QBasic, 17 bytes
This code is very weird.
```
DO
i=11+a(i)
LOOP
```
### How it works
In QBasic, variables are preinitialized. A regular variable without any type suffix, like `i` here, is preinitialized to zero.
Except if you try to subscript into that variable like an array... in which case, it's an array of 11 zeros.\*
On the first time through the loop, therefore, `i` is `0` and `a` is an array. `a(i)` gives the zeroth element of the array (which is `0`). All well and good. We set `i` to `11` and loop. But now `11` is not a valid index for the array `a`, and the program halts with `Subscript out of range`.
A 19-byte version that better shows what's going on:
```
DO
?a(i)
i=i+1
LOOP
```
This will print `0` eleven times before erroring.
---
*\* Conceptually, it's a 10-element array. Most things in QBasic are 1-indexed, but arrays aren't, possibly for implementation reasons. To make things work as expected for programmers, QBasic throws in an extra entry so you can use indices 1 to 10. Index 0, however, is still perfectly accessible. Go figure.*
[Answer]
# **MATLAB, 18 bytes**
This can be run as a script:
```
for j=1:2;j(j);end
```
The first iteration is fine, since `j(1)` is just `1`. The second iteration crashes with an array out of bounds error, as `j(2)` exceeds the dimensions of `j`, which is a 1x1 array.
This also can be run as a script, but it only works the first time you run it. Still, it's a hilarious enough abuse of MATLAB's predefined constants that I thought I'd include it. It's also 18 bytes.
```
while i/i;i={};end
```
When run in a workspace that the variable `i` hasn't been defined in yet, this assumes `i` is the imaginary unit, so `i/i = 1`. In the first loop, the assignment `i={}` creates an empty cell array called `i`. On the second iteration, the loop exits with "Undefined operator '/' for input arguments of type 'cell'."
[Answer]
# [Perl 6](http://perl6.org/), 13 bytes
```
loop {5[$++]}
```
Indexes an integer literal in an infinite loop.  
Relies on fact that on scalar values, the array indexing syntax can be used with index `0` (returning the value itself), but throws an `Index out of range` error for any other index.
[Answer]
## [CJam](https://sourceforge.net/p/cjam), 4 bytes
```
1{}g
```
[Try it online!](https://tio.run/nexus/cjam#@29YXZv@/z8A "CJam – TIO Nexus")
The first iteration of the empty `{}g` loop pops the `1`, which tells it to continue. The second iteration tries to pop another conditional, but the stack is empty, so the program crashes.
[Answer]
## Haskell, 15 bytes
```
f(a:b)=f b
f"a"
```
`f"a"` runs recursively through the string "a" by dropping the first char and eventually fails at its end with a `Non-exhaustive patterns in function f` exception, because `f` is only defined for non-empty strings.
[Answer]
# Pyth, 3 bytes
```
W1w
```
[Try it online.](https://pyth.herokuapp.com/?code=W1w&debug=1)
`W1` is just `while 1:` in Python. The loop body prints a line read from STDIN, which crashes for the second iteration when the code is run with empty input.
If loops using `#` (loop-until-error) are banned (I assume so), I think this is the shortest it can get.
[Answer]
# C#, ~~71~~ 38 bytes
Since you provided an example in C# here another version golfed
And thanks to pinkfloydx33
```
void c(){checked{for(uint i=1;;i--);}}
```
Shorter than `Parse.ToString()` and even than `Parse($"{c--}")`
I mentally dumped `checked` for it being too long of a keyword. Tough it certainly is shorter than `Parse(c.ToString())`
# Original answer
```
class p{static void Main(){for(int c=0;;c--)uint.Parse(c.ToString());}}
```
This will start `c=0` then decrement it, when `c=-1` the `uint.Parse` will cause an:
```
Unhandled Exception: System.OverflowException: Value was either too large or too small for a UInt32.
```
Ungolfed version and verifying that loop runs at least once
```
class p {
    static void Main() {
        for(int c=0;;c--) {
            System.Console.Write(c);
            uint.Parse(c.ToString());
        }
    }
}
```
[Answer]
# CJam, 4 bytes
```
P`:~
```
`P``  generates the string `3.141592653589793`. `:~` evaluates each character. `3` is valid code in CJam which simply returns 3. In the next iteration, `.` causes an error because it requires a digit or an operator following it.
[Answer]
# JavaScript, 9 bytes
```
for(;;i);
```
This runs once, then throws `ReferenceError: i is not defined` which stops the loop.
```
// With a console.log(1) to see that it runs once.
for(;;i)console.log(1);
```
---
Taking the following as an example, is the `<increment>` the end of the first cycle or the beginning of the second cycle ?
```
0:for(<init>;<test>;<increment>)
1:{
2:  <statement>;
3:}
```
### 1/ I see it
After going from lines 0 to line 3 then going **back** to line 0, it feels like a full cycle has been completed.  
That would make the `<increment>` the beginning of the second cycle.  
- First cycle : `<init>` -> `<test>` -> `<statement>`  
- Second cycle : `<increment>` -> `<test>` -> `<statement>`
### 2/ `While` equivalent
```
0:<init>;
1:while(<test>)
2:{
3:  <statement>;
4:  <increment>;
5:}
```
In this equivalent `while` the `<increment>` is the end of the first cycle and it feels like it's the same with the `for`.  
That would make the `<increment>` the end of the first cycle.  
- First cycle : `<test>` -> `<statement>` -> `<increment>`  
- Second cycle : `<test>` -> `<statement>` -> `<increment>` 
### 3/ A statement is encountered twice
A full cycle is completed when a statement is encountered twice.  
The first statement encountered twice is `<test>`.  
That would make the `<increment>` the end of the first cycle.  
- First cycle : `<test>` -> `<statement>` -> `<increment>`  
- Second cycle : `<test>` -> `<statement>` -> `<increment>`
### 4/ It's a setup
The `<init>` is just setting up whatever is needed for the first cycle.  
The `<increment>` is just setting up whatever is needed for the second cycle.  
That would make the `<increment>` the beginning of the second cycle.  
- First cycle : `<init as a setup>` -> `<test>` -> `<statement>`  
- Second cycle : `<increment as a setup>` -> `<test>` -> `<statement>`
---
[The ECMAScript® 2016 Language Specification](http://www.ecma-international.org/ecma-262/7.0/index.html#sec-for-statement-runtime-semantics-labelledevaluation)
Runtime of `for(<init>;<test>;<increment>)<statement>;`
> 
> Let varDcl be the result of evaluating `<init>`.  
> 
>  ReturnIfAbrupt(varDcl).  
> 
>  Return ? ForBodyEvaluation(`<test>`, `<increment>`, `<statement>`, « », labelSet). 
> 
> 
> 
There are three forms, so I took the shortest one here, there's no difference:  
- Whatever the `<init>` it isn't part of the first iteration.  
- What's relevant is in ForBodyEvaluation. 
[Details of ForBodyEvaluation(`<test>`, `<increment>`, `<statement>`, « », labelSet)](http://www.ecma-international.org/ecma-262/7.0/index.html#sec-forbodyevaluation)
> 
> 0 Let V be undefined.  
> 
>  1 Perform ? CreatePerIterationEnvironment(perIterationBindings).  
> 
>  2 Repeat  
> 
>  3  If is not [empty], then  
> 
>  4   Let testRef be the result of evaluating `<test>`.  
> 
>  5   Let testValue be ? GetValue(testRef).  
> 
>  6   If ToBoolean(testValue) is false, return NormalCompletion(V).  
> 
>  7  Let result be the result of evaluating `<statement>`.  
> 
>  8  If LoopContinues(result, labelSet) is false, return Completion(UpdateEmpty(result, V)).  
> 
>  9  If result.[[Value]] is not empty, let V be result.[[Value]].  
> 
>  10  Perform ? CreatePerIterationEnvironment(perIterationBindings).  
> 
>  11  If is not [empty], then  
> 
>  12   Let incRef be the result of evaluating `<increment>`.  
> 
>  13   Perform ? GetValue(incRef). 
> 
> 
> 
### 6/ I see it
A full cycle a full run of the repeat part.  
That would make the `<increment>` the end of the first cycle.  
- First cycle : `<test>` -> `<statement>` -> `<increment>` / In other words from line 3 to line 13  
- Second cycle : `<test>` -> `<statement>` -> `<increment>` / In other words from line 3 to line 13
### 7/ A cycle is an iteration
A cycle begin with `CreatePerIterationEnvironment`.  
So when `CreatePerIterationEnvironment` is encountered a new cycle begins, thus ending the previous one.  
That would make the `<increment>` the beginning of the second cycle.  
- First cycle : `<test>` -> `<statement>` / In other words from line 1 to line 9  
- Second cycle : `<increment>` -> `<test>` -> `<statement>` / In other words from line 10 looping until line 9
---
Is the `<increment>` the end of the first cycle or the beginning of the second cycle?
> 
>  The right explanation is either 6 or 7.
> 
> 
> 
[Answer]
### x86 assembly (AT&T syntax), 40 bytes
```
f:
mov $1,%eax
A:
div %eax
dec %eax
je A
```
Declares a function f which divides 1 by 1 on its first iteration then attempts to divide 0 by 0 and errors.
[Answer]
## Ruby, 14 Bytes
```
loop{$./=~$.}
```
Exits due to `ZeroDivisionError: divided by 0`
`$. The current input line number of the last file that was read`
[Ruby Docs](http://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/variable.html#colon)
[Answer]
## [><>](https://esolangs.org/wiki/Fish), 3 bytes
```
!]!
```
[Try it here!](https://fishlanguage.com/playground/PPsETZDu8a5nMwLic)
### Explanation
```
!    skip next instruction
 ]   close stack (crash)
  !  skip next instruction (jumping to close stack)
```
[Answer]
# Batch, ~~22~~ 20 bytes
```
:a
set i=%i%1
goto a
```
**Explanation**
This is an infinite loop that appends a `1` onto an initially empty string. Eventually this will pass the maximum string length of 8192 and crash. On my machine, this takes about 30 seconds.
[Answer]
# [INTERCAL](http://esolangs.org/wiki/INTERCAL), 12 bytes
```
(1)DO(1)NEXT
```
[Try it online!](https://tio.run/nexus/intercal#@69hqOniDyT8XCNC/v8HAA "INTERCAL – TIO Nexus")
`NEXT` is INTERCAL-72's main control flow command. (Later revisions introduced `COME FROM`, which became more famous, but it wasn't in the original version of the language; and all finished INTERCAL implementations I'm aware of support `NEXT` for backwards compatibility, with all but one enabling support for it by default. So I don't feel the need to name INTERCAL-72 specifically in the title.)
When using `NEXT` to form a loop, you're supposed to use `RESUME` or `FORGET` in order to free up the space that it uses to remember where the program has been; `RESUME` retroactively makes the `NEXT` into something akin to a function call (although you can return from functions other than the one you're in) whereas `FORGET` makes it into something more similar to a GOTO statement. If you don't do either (and this program doesn't), the program will crash after 80 iterations (this behaviour is actually specified in the INTERCAL specification).
It's somewhat ambiguous whether this counts as unbounded recursion (disallowed in the question); you can certainly use this sort of `NEXT` to implement a function call, in which case it would effectively be a recursive function, but there's not enough information here to determine whether we're doing a function call or not. At least, I'm posting this anyway because it doesn't unambiguously violate the rules, and an INTERCAL implementation that optimized out the "tail call" would not only violate the specification, but also cause most existing programs to break, because returning from the "wrong function" is the main way to do the equivalent of an IF statement.
Here's the resulting error message, as generated by C-INTERCAL:
```
ICL123I PROGRAM HAS DISAPPEARED INTO THE BLACK LAGOON
    ON THE WAY TO 1
        CORRECT SOURCE AND RESUBNIT
```
(Note that the second line is indented with a tab, and the third with eight spaces. This looks correct in a terminal, or in pretty much any program that has tab stops at multiples of 8. However, Markdown has tab stops at multiples of four, violating the assumptions that most older programs make about tabs, so the error message is a little malformatted here.)
[Answer]
# Rust, 23 bytes
```
||for i in 0..{[()][i]}
```
[Try it online!](https://tio.run/##FYwxDoAgEAT7e8WWd4XGWg0lnyAWFhApxAQxFsjbEarNJDsTnztVF3DuPrAgE5Dsnbh@n7siPHzANI7ZsGzGb6UCslAhak4/rlqxm6GF3sNG23TdqKcGBRbqQde21B8 "Rust – Try It Online")
Similar to [TehPers's answer](https://codegolf.stackexchange.com/a/208913/97519), but using a unit type array instead of a string gets rid of the `&`, `..` and `;`
[Answer]
## Python 3, 29 bytes
```
i=1
def x(n):del i;x(i)
x(i)
```
Really simple. On the second call to x, i isn't there, and Python complains about it.
[Answer]
## [Labyrinth](https://github.com/m-ender/labyrinth), 3 bytes
```
#(/
```
[Try it online!](https://tio.run/nexus/labyrinth#@6@sof//PwA "Labyrinth – TIO Nexus")
Like most 2D languages, Labyrinth doesn't have any explicit looping constructs. Instead, any code that is laid out such that it is executed multiple times in a row is a loop in these languages. For the case of Labyrinth, a simple linear program acts as a loop, because the instruction pointer will bounce back and forth on it. If the program is `abc` (for some commands `a`, `b` and `c`), then the actual execution will be `abcbabcbabcb...` so it runs `abcb` in an infinite loop.
As for why this particular program crashes on the second iteration of this loop, here is what the individual commands do. Note that Labyrinth's stack contains an implicit infinite amount of zeros at the bottom:
```
#   Push stack depth.   [... 0]
(   Decrement.          [... -1]
/   Divide.             [... 0]
(   Decrement.          [... -1]
#   Push stack depth.   [... -1 1]
(   Decrement.          [... -1 0]
/   Divide.             Crashes with division-by-zero error.
```
[Answer]
# Bash, 11 (Borderline non-competing)
```
exec $0 1$@
```
This script recursively execs itself, appending `1` to the args passed on each iteration. I think this counts as TCO because exec reuses the process space but doesn't eat up stack. It is borderline non-competing because it took about 10 minutes before being killed on my machine - YMMV.
]