[Question]
  [
Your task is to write a full program that will continue to count down from 10 every time it is run.
* The first time you run the program, it should print `10`.
* The next time, it should output `9`.
* The next time, it should output `8`, and so on.
* Instead of printing `0`, the program should crash. You do not have to handle the program running any more times after that.
* Any facilities used for storage may be assumed to be empty before the first execution of the program.
Here's an example implementation in Python 3:
```
try:f=open("a","r+");v=int(f.read())
except:f=open("a","w");v=10
1/v
print(v)
f.seek(0)
f.write(str(v-1))
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer (measured in bytes) wins.
  
[Answer]
# Perl on Linux, 17 bytes
I thought it might be interesting to create a program that doesn't maintain any state itself, and doesn't modify its own source code; in other words, it actually checks how often it's been run by asking the OS. The question says "Any facilities used for storage may be assumed to be empty before the first execution of the program.", and thus we'd want to start from a completely blank OS. As such, I'd better explain just how you go about doing that, as otherwise testing the program is difficult.
There are actually two ways to set up for running the program. Either way, the minimal OS for the purpose would be running nothing but a shell (to enable us to run Perl in turn), and the simplest possible shell at that (so that it doesn't do anything fancy that makes the OS non-blank). `/bin/dash` is a good choice here, as it was intended as a minimal shell for system recovery. Then, we need to start Linux in such a way that it's running nothing but `dash`. We can either do this by rebooting the computer with `init=/bin/dash` on the Linux command line so that it starts nothing besides `dash`, or (much more conveniently) creating a Linux container using `unshare -Urfp /bin/dash` in a terminal (`unshare` doesn't actually *create* a blank OS, but it does *simulate* one; notably, the inside of the container thinks it's root, `dash` thinks it's init, etc., just as would happen on an actual blank OS). Disclaimer: I haven't actually tested this on bare metal yet, only inside `unshare`, but it should work both ways in theory.
Finally, once we've got that set up, we simply have to look at the PID; as we're on a blank system, the init system (here, the shell) will have PID 1, so the executions of Perl will have PIDs from 2 up to 12 inclusive. So our program looks like this:
```
say 12-$$||die
```
Here's a sample run:
```
$ unshare -Urfp /bin/dash
# perl -E 'say 12-$$||die'
10
# perl -E 'say 12-$$||die'
9
# perl -E 'say 12-$$||die'
8
# perl -E 'say 12-$$||die'
7
# perl -E 'say 12-$$||die'
6
# perl -E 'say 12-$$||die'
5
# perl -E 'say 12-$$||die'
4
# perl -E 'say 12-$$||die'
3
# perl -E 'say 12-$$||die'
2
# perl -E 'say 12-$$||die'
1
# perl -E 'say 12-$$||die'
Died at -e line 1.
#
```
[Answer]
# 6502 machine language + Apple ][+ ROM, 12 (11? 10? 9?) bytes
```
CE 06 80 F0 01 A2 0B A9 00 4C 24 ED
```
Should start at `$8000`. Crashes to the system monitor when the count reaches 0.
---
```
C6 B6 F0 01 A2 0B A9 00 4C 24 ED
```
Should start at `$B1`. This saves a byte since I can use the (two-byte) zero-page version of `DEC`, but overwrites the critical Applesoft routine `CHRGET`; you'll need to load it and call it from the monitor, and use `CTRL`+`B``Return` to re-initialize BASIC once you're done. Not sure if this invalidates it or not.
---
```
CE 06 80 F0 01 A2 0B 4C 26 ED
```
Should start at `$8000`. This doesn't initialize `$9E`, saving two bytes. However, this means you **must not call it with a negative address** (or, if you call it from the monitor, you have to call the monitor with a positive address). If you do, Applesoft's `CALL` routine will store `FF` in `$9E`, causing it to add 65280 to the number when printing it. Again, not sure if this invalidates the solution or not.
---
```
C6 B6 F0 01 A2 0B 4C 26 ED
```
Should start at `$B1`. This is a combination of the above two programs, saving a total of three bytes; you'll have to call the monitor with a positive address, load it and run it from there, and use `Ctrl`+`B``Return` to re-initialize BASIC once you're done.
---
Note that these programs only modify the program in memory; re-loading the program from disk will reset the countdown. This works because the Apple ][ (and ][+, //e, and //c) have no memory protection system whatsoever; the program (and its self-modifications) will stay in memory even after it exits, so you can keep running it from memory until you overwrite that memory with something else.
---
## Sample run
```
]BLOAD COUNT THEN BRK
]CALL 32768
10
]CALL 32768
9
]CALL 32768
8
]CALL 32768
7
]CALL 32768
6
]CALL 32768
5
]CALL 32768
4
]CALL 32768
3
]CALL 32768
2
]CALL 32768
1
]CALL 32768
8008-    A=80 X=9D Y=00 P=36 S=EE
*
```
---
## Explanation
```
     DEC NUM+1  ; Decrement the LDX instruction's operand
     BEQ NUM+1  ; If it is now zero, branch to it; 00 is the opcode for the BRK instruction, which causes the program to crash to the monitor
NUM  LDX #$0B   ; Load the X register with 0x0A; the operand has already been decremented once
     LDA #$00   ; Load the accumulator with 0
     JMP $ED24  ; Jump to $ED24, an Applesoft ROM routine which prints A (high byte),X (low byte) in decimal
```
---
## Explanation of 10 byte version
```
     DEC NUM+1  ; Decrement the LDX instruction's operand
     BEQ NUM+1  ; If it is now zero, branch to it; 00 is the opcode for the BRK instruction, which causes the program to crash to the monitor
NUM  LDX #$0B   ; Load the X register with 0x0A; the operand has already been decremented once
     JMP $ED26  ; Jump to $ED26, which is two bytes into the Applesoft routine at $ED24. The two skipped bytes would store the accumulator in $9E
```
---
# Variants
## Prints `ERR` and beeps when count reaches 0
### Normal - 15 bytes
```
CE 06 80 F0 07 A2 0B A9 00 4C 24 ED 4C 2D FF
```
### Overwrites `CHRGET` - 14 bytes
```
C6 B6 F0 07 A2 0B A9 00 4C 24 ED 4C 2D FF
```
### Doesn't initialize `$9E` - 13 bytes
```
CE 06 80 F0 05 A2 0B 4C 26 ED 4C 2D FF
```
### Overwrites `CHRGET` and doesn't initialize `$9E` - 12 bytes
```
C6 B6 F0 05 A2 0B 4C 26 ED 4C 2D FF
```
---
## Freezes when count reaches 0
### Normal - 12 bytes
```
CE 06 80 F0 FE A2 0B A9 00 4C 24 ED
```
### Overwrites `CHRGET` - 11 bytes
```
C6 B6 F0 FE A2 0B A9 00 4C 24 ED
```
### Doesn't initialize `$9E` - 10 bytes
```
CE 06 80 F0 FE A2 0B 4C 26 ED
```
### Overwrites `CHRGET` and doesn't initialize `$9E` - 9 bytes
```
C6 B6 F0 FE A2 0B 4C 26 ED
```
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + sed, ~~41~~ ~~40~~ 38 bytes
```
echo $[n=10/1]
sed -i s/$n/$[n-1]/g $0
```
[Try it online!](https://tio.run/nexus/bash#TYxBC4IwHEfP7lP8IMkKdK5r5s0gCAzqFhHTLd3B/8BpBtVnN7t1evB4vFJ2SFHanjplB0KSIMjyXTDqsrbwL7QVMRdX5rRCaOC4T3yyobjyCn48Ti1jd9viBkN4iTiK4s8GyjKvkK7@O6/TucCbed5vFTg@IVodddsY54wlKE1GK84DzNDqxj60gyScsoOh/olBtmSowuK8z1H01ZJ5ypIevw "Bash – TIO Nexus")
[Answer]
## Javascript, 42 bytes
```
y=localStorage;y.a=y.a||10;alert(y.a--||a)
```
Test it out with [this fiddle](https://jsfiddle.net/3runz3mx/) - be sure to clear your local storage to reset the countdown.
Thanks to steenbergh, Lmis, and obarakon for lots of bytes!
[Answer]
# [Dyalog APL](http://goo.gl/9KrKoM), ~~33~~ ~~28~~ 22/20? [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319)
I am not sure if this is valid, as it consists of a function (which must be called with a dummy argument). However, all APL programs (purely functional or not) have the same status, and indeed some APL versions do not have traditional programs, only functions. In compensation, I have added two bytes to name it, although that is not necessary for the desired effect.
```
f←{6::⊢c∘←10⋄÷÷c∘←c-1}
```
Note that this relies on an unofficial quirk, that `∘←` assigns globally.
`6::` upon any value error
`⊢c` return *c*
`∘←10` which is globally set to 10
`⋄` now
`÷÷c` return the twice inverted (errors on zero) c
`∘←` which is globally set to
`c-1` one less than *c*
[TryAPL online!](http://tryapl.org/?a=f%u2190%7B6%3A%3A%u22A2c%u2218%u219010%u22C4%F7%F7c%u2218%u2190c-1%7D%20%u22C4%20f%u236C%20%u22C4%20f%u236C%20%u22C4%20f%u236C%20%u22C4%20f%u236C%20%u22C4%20f%u236C%20%u22C4%20f%u236C%20%u22C4%20f%u236C%20%u22C4%20f%u236C%20%u22C4%20f%u236C%20%u22C4%20f%u236C%20%u22C4%20f%u236C&run)
---
Certainly valid 28 byte version:
```
f
⍎'c←11'/⍨0=⎕NC'c'
⊢c←÷÷c-1
```
Works by setting *c* to 11 if missing, then subtracting 1 from *c*, inverting twice (which gives div-by-zero error if *c*-1 is 0), assigning to *c*, and outputting the new value.
---
Old 33 byte version:
```
f
÷÷≢2↓r⊣⎕FX¯1↓r←⎕NR'f'
    
    
    
    
    
    
    
    
    
```
Works by redefining itself on each run, but with one less trailing newline. Outputs the twice inverted number of remaining lines (less two), thus giving a div-by-zero error when only two lines are left (the header and the actual code).
[Answer]
## C#, ~~197~~ ~~160~~ ~~159~~ 125 bytes
```
namespace System.IO{class P{static void Main(){int n=11;for(;File.Exists(""+--n););File.Create(""+n);Console.Wr‌​ite(n*n/n);}}}
```
*Saved 34 bytes thanks to milk*
And a formatted version (With `ReadKey` added so you can view the output):
```
namespace System.IO
{
    class P
    {
        static void Main()
        {
            int n=11;
            for(;File.Exists(""+--n););
            File.Create(""+n);
            Console.Wr‌​ite(n*n/n);
        }
    }
}
```
It is longer than I thought it would be so there's probably room for golfing.
[Answer]
# Perl, ~~37~~ 36 bytes
```
9=~//;print$'-sysopen$~,$0,print$'+1
```
Crashes when the initial value reaches -1 (which would have printed 0), as it writes over the `=~` operator.
Saved a byte using `sysopen` rather than `open`. This allows me to print to `STDOUT` first, using the return value as the file mode (`1`, a.k.a. `O_WRONLY`), before `$~` is reassigned.
**Sample Usage**
```
$ perl crash-off.pl
10
$ perl crash-off.pl
9
$ perl crash-off.pl
8
...
$ perl crash-off.pl
2
$ perl crash-off.pl
1
$ perl crash-off.pl
syntax error at crash-off.pl line 1, near "1~"
Execution of crash-off.pl aborted due to compilation errors.
```
[Answer]
# [Perl 6](https://perl6.org), ~~60~~ 58 bytes
```
put 10-$=finish.lines||die;
$*PROGRAM.open(:a).put;
=finish
 
```
```
open($*PROGRAM,a=>put 10-$=finish.lines||die).put
=finish
 
```
Needs newline character after `=finish`.
`die` can be replaced with `1/0`.
## Explanation:
It gets a list of lines after `=finish` (`$=finish.lines`) subtracts that from `10`, and if the result isn't `0` it prints it, otherwise it `die`s.
The last thing it does is open itself in append mode, and add another line to the end.
[Answer]
# Python 2, 65 bytes
```
f=open(__file__,"r+")
x=75-len(f.read())
x/x
print x
f.write('#')
```
Inspired by [L3viathan's answer](https://codegolf.stackexchange.com/a/103344/62501).
Can be reduced to 60 bytes if you can choose to name the file a single character like `x` and then replace `__file__` with `'x'`. In that case, replace `75` with `70`.
[Answer]
# Jolf, 20 bytes
```
γ-@▲lqΈ?␡γ?γaγ0₯I₯C1
```
[Try it here!](http://conorobrien-foxx.github.io/Jolf/#code=zrMtQB5scc6IP3_Osz_Os2HOszDigq9J4oKvQzE) Errors when `0` is printed. Modifies the code. Explanation to come.
[Answer]
# Applesoft BASIC, 21 bytes (tokenized)
```
0  PRINT 9 + 1: CALL 2066: END : OR <CTRL-F><CTRL-H>`
```
Replace `<CTRL-F>` and `<CTRL-H>` with their literal versions. Note that this only modifies the program in memory; re-loading it from the disk will reset the countdown.
---
## Sample run
```
]RUN
10
]RUN
9
]RUN
8
]RUN
7
]RUN
6
]RUN
5
]RUN
4
]RUN
3
]RUN
2
]RUN
1
]RUN
?SYNTAX ERROR IN 0
```
---
## Explanation
`PRINT 9 + 1` does what you'd expect. `CALL 2066` calls the 6502 machine-language routine at memory location 2066, which is after `END :`. `END` halts the program so that the machine-language routine (which, to the Applesoft interpreter, is garbage) isn't executed.
The machine-language routine simply decrements the `9` in `PRINT 9 + 1`. Disassembly:
```
0812-   CE 06 08    DEC $0806
0815-   60          RTS
```
After the counter reaches 0, it is "decremented" to `/`; attempting to run the program will then cause a syntax error.
[Answer]
## [\*><>](http://esolangs.org/wiki/Starfish), ~~20~~ 18 bytes
```
a1Fi:0(?b1-:?:1Fn;
```
This actually works on Linux (and whatever supports files named `\n` I guess). It creates a file named `\n` on first run and outputs `10`. It proceeds to output one less number on each subsquent run, except `0` where it crashes instead.
### Explanation
```
a1F                   open file named "\n"
   i:                 recieve input and duplicate it (-1 if empty)
     0(?b             if the file is empty, push 11 to the stack
         1-           subtract one
           :          duplicate the number
            ?:        if the number isn't 0, duplicate it again
              1F      save the number to the file
                n     output the number (crash if non-existant)
                 ;    exit
```
[Answer]
# PHP 57 bytes
```
echo$n=($f=file(f))?$f[0]:10?:die;fputs(fopen(f,w),--$n);
```
doesn´t really crash but exit (without counting down) when it hits `0`. Is that sufficient?
Run with `-r`.
[Answer]
# C#, 156 bytes
I golfed @TheLethalCoder's answer for a bit, and was able to save 3 bytes by reordering the statements and eliminating the int.parse(). Still room for improvement, I'm sure.
```
using System.IO;class P{static void Main(){int n;try{n=File.ReadAllText("f")[0]-48;}catch{n=10;}System.Console.Write(n/n*n);File.WriteAllText("f",""+--n);}}
```
Ungolfed:
```
using System.IO;
class P
{
    static void Main()
    {
        int n;
        try
        {
            n = File.ReadAllText("f")[0] - 48;
        }
        catch {
            n = 10;
        }
        System.Console.Write(n / n * n);
        File.WriteAllText("f", "" + --n);
    }
}
```
Meta-question: It may be hack-y to take TheLethalCoder's work as a starting point for my answer. Would it be better (once I have the rep) to add this as a comment on their answer? I'm not trying to compete with them, I just want to show off my golf, for mutual edification.
[Answer]
## Powershell V2.0, 49 bytes
(First ever code golf, couldn't find the rules on how to calculate bytes. I used a String to bytes calculator online)
```
if(!$n){$n=10;$n}else{$n-=1;if($n-eq0){throw};$n}
```
Running:
```
PS C:\Users\***> if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw};$n;}
10
____________________________________________________________________________________________________________________________________________________________________
PS C:\Users\***> if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw};$n;}
9
____________________________________________________________________________________________________________________________________________________________________
PS C:\Users\***> if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw};$n;}
8
____________________________________________________________________________________________________________________________________________________________________
PS C:\Users\***> if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw};$n;}
7
____________________________________________________________________________________________________________________________________________________________________
PS C:\Users\***> if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw};$n;}
6
____________________________________________________________________________________________________________________________________________________________________
PS C:\Users\***> if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw};$n;}
5
____________________________________________________________________________________________________________________________________________________________________
PS C:\Users\***> if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw};$n;}
4
____________________________________________________________________________________________________________________________________________________________________
PS C:\Users\***> if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw};$n;}
3
____________________________________________________________________________________________________________________________________________________________________
PS C:\Users\***> if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw};$n;}
2
____________________________________________________________________________________________________________________________________________________________________
PS C:\Users\***> if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw};$n;}
1
____________________________________________________________________________________________________________________________________________________________________
PS C:\Users\***> if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw};$n;}
ScriptHalted
At line:1 char:49
+ if(!$n){$n = 10;$n}else{$n=$n-1;if($n-eq0){throw <<<< };$n;}
    + CategoryInfo          : OperationStopped: (:) [], RuntimeException
    + FullyQualifiedErrorId : ScriptHalted
```
[Answer]
## Java, 343 bytes
My first golfing attempt 
```
import java.io.PrintWriter;class M{public static void main(String[] a) throws Exception{if(!new java.io.File("x").exists()) try(PrintWriter p=new java.io.PrintWriter("x")){p.write("10");}int b=new java.util.Scanner(new java.io.File("x")).nextInt();try(PrintWriter p=new java.io.PrintWriter("x")){p.print(b/b*b-1+"");System.out.print(b+"");}}}
```
ungolfed
```
import java.io.PrintWriter;
class M {
    public static void main(String[] a) throws Exception {
        if (!new java.io.File("x").exists()) {
            try (PrintWriter p = new java.io.PrintWriter("x")) {
                p.write("10");
            }
        }
        int b = new java.util.Scanner(new java.io.File("x")).nextInt();
        try (PrintWriter p = new java.io.PrintWriter("x")) {
            p.print(b / b * b - 1 + "");
            System.out.print(b + "");
        }
    }
}
```
[Answer]
# SQLite, ~~142~~ 137
This could probably be done much more cleverly. ~~141~~ 136 chars for code:
```
create table if not exists t(n not null);insert into t select 11;update t set n=case n when 1 then null else n-1 end;select min(n)from t
```
Plus 1 for the filename `x` in `sqlite3 x '…'`.
[Answer]
## JavaScript, 74 bytes
~~`x=typeof x!=typeof 1?10:x!=1?x-=1:_`~~
`l=localStorage;l.a=typeof l.a!=typeof""?10:l.a!=1?l.a=--l.a:_;aler‌​t(l.a)`
[Answer]
## Ruby, ~~94~~ ~~87~~ ~~84~~ ~~61~~ 59 bytes
```
j=File.open(?a,"a+");1/(i=j.readlines.size-14);p -i;j.puts
```
Please leave suggestions below.
Thanks @ConorO'Brien for the ideas (some shamelessly ripped off from his answer).
[Answer]
# Ruby, 52 + 1 = 53 bytes
Assumes the file is named `a` (+1 byte).
```
q=File.read ?a
0/h=62-q.size
p h
File.write ?a,q+?1#
```
## Running
```
C:\Users\Conor O'Brien\Documents\Programming
λ type a
q=File.read ?a
0/h=62-q.size
p h
File.write ?a,q+?1#
C:\Users\Conor O'Brien\Documents\Programming
λ ruby a
10
C:\Users\Conor O'Brien\Documents\Programming
λ ruby a
9
C:\Users\Conor O'Brien\Documents\Programming
λ ruby a
8
C:\Users\Conor O'Brien\Documents\Programming
λ ruby a
7
C:\Users\Conor O'Brien\Documents\Programming
λ ruby a
6
C:\Users\Conor O'Brien\Documents\Programming
λ ruby a
5
C:\Users\Conor O'Brien\Documents\Programming
λ ruby a
4
C:\Users\Conor O'Brien\Documents\Programming
λ ruby a
3
C:\Users\Conor O'Brien\Documents\Programming
λ ruby a
2
C:\Users\Conor O'Brien\Documents\Programming
λ ruby a
1
C:\Users\Conor O'Brien\Documents\Programming
λ ruby a
a:2:in `/': divided by 0 (ZeroDivisionError)
        from a:2:in `<main>'
```
[Answer]
# Python 2, 89 bytes
```
x=10
x/x
print x
f=open(__file__,"r+")
s=f.read()
f.seek(0)
f.write(s.replace(`x`,`x-1`))
```
[Answer]
# TI-BASIC (TI-84 Plus) (15 bytes)
```
If not(Ans
11
Ans-1
AnsAns/Ans
```
Ans should equal 0 (the default value) before the first run.
Since `AnsAns/Ans` is the last line of the program, it will be outputted and stored to Ans unless Ans is 0, in which case a divide by 0 error occurs.
[Answer]
# JavaScript, 41
`l=localStorage;l.l=-~l.l;alert(11-l.l||I)`
[Answer]
# GNU Smalltalk, ~~70~~, 68 bytes
66 bytes code +2 bytes for the "-S" flag
EDITS
* Removed unnecessary parentheses, -2 bytes
**Golfed**
```
X=Y ifTrue:[Smalltalk at:#X put:10]ifFalse:[X:=X-1].(X*X/X)printNl
```
**Test**
```
>seq 11|xargs -L1 sudo gst -S fail.st 2>/dev/null
10
9
8
7
6
5
4
3
2
1
Object: 0 error: The program attempted to divide a number by zero
ZeroDivide(Exception)>>signal (ExcHandling.st:254)
SmallInteger(Number)>>zeroDivide (SysExcept.st:1426)
SmallInteger>>/ (SmallInt.st:277)
UndefinedObject>>executeStatements (fail.st:1)
```
*Important*
You must run *gst* as root, for it to be able to modify the default image, or specify your own image with *-I*.
[Answer]
# PHP, 45 bytes
Honestly not sure if this one counts.
```
<?session_start();echo10-$_SESSION[0]++?:die;
```
I'd post a link to an example, but all the online testers that I know don't allow `session_start()` to be used.
This will keep counting down each time you refresh the page until 0, when the `die` command is ran.
[Answer]
## [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), 70 bytes
```
open"r",1,"a.b" $get#1,1,e|~e=0|e=z\e=e-1]?e~e=0|$error 1|]$put#1,1,e|
```
Opens file `a.b` (or creates it when not found on first run), reads record 1 into `e`. If that record is not found, assume 10, else sub 1. At `e==0`, raise an error. Write back `e` to `a.b`.
File access is not built into QBIC, this relies heavily on the underlying QBasic.
[Answer]
## Batch, 72 bytes
```
@call:l
@if %n%==0 goto g
@echo %n%
@cmd/cset/a-1>>%0
:l
@set/an=10
```
Needs to be invoked using the full file name including extension. Last line must not have a trailing newline. Works by writing `-1` to the end of the last line so that it evaluates to 1 less each time. `goto g` errors out because there's no label `:g`.
[Answer]
## R, 52 bytes
```
`if`(!"x"%in%ls(),cat(x<-10),`if`(x>0,cat(x<-x-1),))
```
Essentially uses `ls()` to list the names of all globally stored objects. If we assume that the global environment is empty and `"x"` doesn't exist already, generate `x=10`, else if `x!=0` subtract `1` else call a missing argument which returns an error.
[Answer]
## Windows Batch, 61 bytes
```
@if %n%.==. set n=10
@if %n%==0 goto.
@set /a n-=1&@echo %n%
```
[Answer]
**JavaScript, 44 bytes**
```
function* f(n=11){for(;--n;yield n);throw''}
p=f()
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
```
]