Loops/Downward for: Difference between revisions

m
→‎{{header|ALGOL-M}}: added workaround
(add BQN)
m (→‎{{header|ALGOL-M}}: added workaround)
 
(38 intermediate revisions by 19 users not shown)
Line 25:
 
=={{header|11l}}==
<langsyntaxhighlight lang="11l">L(i) (10..0).step(-1)
print(i)</langsyntaxhighlight>
 
=={{header|360 Assembly}}==
Use of BXLE and BCT opcodes.
<langsyntaxhighlight lang="360asm">* Loops/Downward for 27/07/2015
LOOPDOWN CSECT
USING LOOPDOWN,R12
Line 55:
BUFFER DC CL80' '
YREGS
END LOOPDOWN</langsyntaxhighlight>
 
=={{header|6502 Assembly}}==
Code is called as a subroutine (i.e. JSR Start).
Printing routines are only partially coded here, specific OS/hardware routines for printing are left unimplemented.
<langsyntaxhighlight lang="6502asm">;An OS/hardware specific routine that is setup to display the Ascii character
;value contained in the Accumulator
Send = $9000 ;routine not implemented here
Line 97:
ORA #$30
JSR Send ;routine not implemented here
RTS </langsyntaxhighlight>
 
=={{header|68000 Assembly}}==
Code is called as a subroutine, i.e. "JSR ForLoop." OS/Hardware specific printing subroutines are unimplemented here.
<langsyntaxhighlight lang="68000devpac">ForLoop:
MOVE.W #10,D0
loop:
JSR Print_D0_As_Ascii ;some routine that converts the digits of D0 into ascii characters and prints them to screen.
DBRA D0,loop ;repeat until D0.W = $FFFF
rts</langsyntaxhighlight>
 
=={{header|8080 Assembly}}==
This assumes the CP/M operating system.
<syntaxhighlight lang="asm">
;-------------------------------------------------------
; some useful equates
;-------------------------------------------------------
bdos equ 5h ; location ofjump to BDOS entry point
wboot equ 0 ; BDOS warm boot function
conout equ 2 ; write character to console
;-------------------------------------------------------
; main code
;-------------------------------------------------------
org 100h
lxi sp,stack ; set up a stack
;
lxi h,10 ; starting value for countdown
loop: call putdec ; print it
mvi a,' ' ; space between numbers
call putchr
dcx h ; decrease count by 1
mov a,h ; are we done (HL = 0)?
ora l
jnz loop ; no, so continue with next number
jmp wboot ; otherwise exit to operating system
;-------------------------------------------------------
; console output of char in A register
; preserves BC, DE, HL
;-------------------------------------------------------
putchr: push h
push d
push b
mov e,a
mvi c,conout
call bdos
pop b
pop d
pop h
ret
;---------------------------------------------------------
; Decimal output to console routine
; HL holds 16-bit unsigned binary number to print
; Preserves BC, DE, HL
;---------------------------------------------------------
putdec: push b
push d
push h
lxi b,-10
lxi d,-1
putdec2:
dad b
inx d
jc putdec2
lxi b,10
dad b
xchg
mov a,h
ora l
cnz putdec ; recursive call!
mov a,e
adi '0' ; make printable
call putchr
pop h
pop d
pop b
ret
;----------------------------------------------------------
; data area
;----------------------------------------------------------
stack equ $+128 ; 64-level stack to support recursion
;
end
</syntaxhighlight>
{{out}}
<pre>
10 9 8 7 6 5 4 3 2 1
</pre>
 
 
=={{header|8086 Assembly}}==
It is typically much easier for assembly languages to loop downwards than forwards, as they can do so without using a redundant equality check. The 8086's <code>LOOP</code> instruction will loop a section of code, using the <code>CX</code> register as the loop counter.
 
<langsyntaxhighlight lang="asm"> .model small ;.exe file, max 128 KB
.stack 1024 ;reserve 1 KB for the stack pointer.
Line 169 ⟶ 247:
ret
 
end start ;EOF</langsyntaxhighlight>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program loopdownward64.s */
Line 224 ⟶ 302:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">for I in reverse 0..10 loop
Put_Line(Integer'Image(I));
end loop;</langsyntaxhighlight>
 
=={{header|Agena}}==
Tested with Agena 2.9.5 Win32
<langsyntaxhighlight lang="agena">for i from 10 downto 0 do
print( i )
od</langsyntaxhighlight>
 
=={{header|ALGOL 60}}==
{{works with|A60}}
'''Based on the 1962 Revised Repport on ALGOL''':
'''Based on the 1962 Revised Report on ALGOL''':
'''begin'''
'''integer''' i;
'''for''' i:=10 '''step''' -1 '''until''' 0 '''do'''
outinteger(1,i)
'''end'''
{{works with|ALGOL 60|OS/360}}
<langsyntaxhighlight lang="algol60">'BEGIN' 'COMMENT' Loops/Downward for - Algol60 - 23/06/2018;
'INTEGER' I;
'FOR' I := 10 'STEP' -1 'UNTIL' 0 'DO'
OUTINTEGER(1,I)
'END'</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
Line 254 ⟶ 333:
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386}}
<langsyntaxhighlight lang="algol68">FOR i FROM 10 BY -1 TO 0 DO
print((i,new line))
OD</langsyntaxhighlight>
As a common extension the DOWNTO is sometimes included to optimise
the loop termination logic. The DOWNTO is available in Marcel's
[[ALGOL 68G]] and [[Cambridge ALGOL 68C]].
<langsyntaxhighlight lang="algol68">FOR i FROM 10 DOWNTO 0 DO
print((i,new line))
OD</langsyntaxhighlight>
 
=={{header|ALGOL-M}}==
Sadly, ALGOL-M's FOR statement does not allow a negative value
for STEP, so in order to count down we either have to use a WHILE loop
or move the subtraction into the body of the FOR loop
<syntaxhighlight lang="ALGOL">
begin
 
integer i;
 
write("First approach :");
i := 10;
while (i >= 0) do
begin
writeon(i);
i := i - 1;
end;
 
write("Second approach:");
for i := 0 step 1 until 10 do
writeon(10-i);
 
end
</syntaxhighlight>
{{out}}
<pre>
First approach : 10 9 8 7 6 5 4 3 2 1 0
Second approach: 10 9 8 7 6 5 4 3 2 1 0
</pre>
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
for i := 10 step -1 until 0 do
begin
write( i )
end
end.</langsyntaxhighlight>
 
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="amazing hopper">
#include <flow.h>
 
DEF-MAIN
CLR-SCR
SET(i, 10)
LOOP(ciclo abajo)
PRNL(i)
BACK-IF-NOT-ZERO(i--, ciclo abajo)
END
</syntaxhighlight>
{{out}}
<pre>
10
9
8
7
6
5
4
3
2
1
0
</pre>
=={{header|AmigaE}}==
<langsyntaxhighlight lang="amigae">PROC main()
DEF i
FOR i := 10 TO 0 STEP -1
WriteF('\d\n', i)
ENDFOR
ENDPROC</langsyntaxhighlight>
 
=={{header|AppleScript}}==
<langsyntaxhighlight AppleScriptlang="applescript">repeat with i from 10 to 0 by -1
log i
end repeat</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
 
/* ARM assembly Raspberry PI */
Line 402 ⟶ 536:
 
 
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
<langsyntaxhighlight lang="rebol">loop 10..0 'i [
print i
]</langsyntaxhighlight>
 
{{out}}
Line 422 ⟶ 556:
1
0</pre>
 
=={{header|Asymptote}}==
Asymptote's control structures are similar to those in C, C++, or Java
<syntaxhighlight lang="asymptote">for(int i = 10; i >=0; --i) {
write(i);
}</syntaxhighlight>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">x := 10
While (x >= 0)
{
Line 431 ⟶ 571:
}
MsgBox % output
</syntaxhighlight>
</lang>
 
=={{header|Avail}}==
<langsyntaxhighlight Availlang="avail">For each i from 10 to 0 by -1 do [Print: “i” ++ "\n";];</langsyntaxhighlight>
Note that <code>10 to 0 by -1</code> section isn't a fixed part of the loop syntax, but a call to the <code>_to_by_</code> method, which returns a tuple of integers in a range separated by a particular step size, in this case returning <code><10, 9, 8, 7, 6, 5, 4, 3, 2, 1></code>.
 
=={{header|AWK}}==
<langsyntaxhighlight lang="awk">BEGIN {
for(i=10; i>=0; i--) {
print i
}
}</langsyntaxhighlight>
 
=={{header|Axe}}==
Axe does not support for loops with step sizes other than 1.
<langsyntaxhighlight lang="axe">For(I,0,10)
Disp 10-I▶Dec,i
End</langsyntaxhighlight>
 
=={{header|Bait}}==
<syntaxhighlight lang="bait">
fun main() {
for i := 10; i >= 0; i -= 1 {
println(i)
}
}
</syntaxhighlight>
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<langsyntaxhighlight ApplesoftBasiclang="applesoftbasic">FOR I = 10 TO 0 STEP -1 : PRINT I : NEXT I</langsyntaxhighlight>
 
==={{header|BaCon}}===
<langsyntaxhighlight lang="freebasic">' Downward for
FOR i = 10 DOWNTO 0 : PRINT i : NEXT</langsyntaxhighlight>
 
==={{header|BASIC256}}===
{{works with|QBasic}}
<langsyntaxhighlight BASIC256lang="basic256">for i = 10 to 0 step -1
print i; " ";
next i
print
end</langsyntaxhighlight>
 
==={{header|BBC BASIC}}===
<langsyntaxhighlight lang="bbcbasic"> FOR i% = 10 TO 0 STEP -1
PRINT i%
NEXT</langsyntaxhighlight>
 
==={{header|Commodore BASIC}}===
<langsyntaxhighlight lang="basic">10 FOR I = 10 TO 0 STEP -1
20 PRINT I
30 NEXT</langsyntaxhighlight>
 
==={{header|Chipmunk Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|FBSL}}===
<syntaxhighlight lang="qbasic">#APPTYPE CONSOLE
 
FOR DIM i = 10 DOWNTO 0
PRINT i
NEXT
 
PAUSE</syntaxhighlight>
 
==={{header|FreeBASIC}}===
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
For i As Integer = 10 To 0 Step -1
Line 483 ⟶ 644:
Next
Print
Sleep</langsyntaxhighlight>
{{out}}
<pre> 10 9 8 7 6 5 4 3 2 1 0</pre>
<pre>
10 9 8 7 6 5 4 3 2 1 0
</pre>
 
==={{header|FutureBasic}}===
<langsyntaxhighlight lang="futurebasic">
window 1, @"Countdown", ( 0, 0, 400, 300 )
include "ConsoleWindow"
 
NSInteger i
dim as long i
 
for i = 10 to 0 step -1
print i
next
 
</lang>
HandleEvents</syntaxhighlight>
Output:
<pre> 10
10
9
8
Line 511 ⟶ 670:
2
1
0</pre>
</pre>
 
==={{header|Gambas}}===
'''[https://gambas-playground.proko.eu/?gist=b236db5bdb1087fa90e934a5a8210e1f Click this link to run this code]'''
<langsyntaxhighlight lang="gambas">Public Sub Main()
Dim siCount As Short
 
Line 523 ⟶ 681:
Next
 
End</langsyntaxhighlight>
Output:
<pre>10 9 8 7 6 5 4 3 2 1 0</pre>
<pre>
10 9 8 7 6 5 4 3 2 1 0
</pre>
 
==={{header|GW-BASIC}}===
{{works with|BASICA}}
{{works with|PC-BASIC|any}}
<syntaxhighlight lang="gwbasic">10 FOR I% = 10 TO 0 STEP -1
<lang qbasic>
10 FOR I% = 10 TO 0 STEP -1
20 PRINT I%
30 NEXT I%</syntaxhighlight>
</lang>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 FOR I=10 TO 0 STEP-1
110 PRINT I
120 NEXT</langsyntaxhighlight>
 
==={{header|Liberty BASIC}}===
{{works with|Just BASIC}}
<lang lb>
{{works with|Run BASIC}}
for i = 10 to 0 step -1
<syntaxhighlight lang="lb">for i = 10 to 0 step -1
print i
next i
end</langsyntaxhighlight>
 
==={{header|Microsoft Small Basic}}===
<langsyntaxhighlight lang="microsoftsmallbasic">
For i = 10 To 0 Step -1
TextWindow.WriteLine(i)
EndFor</langsyntaxhighlight>
 
==={{header|MSX Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|NS-HUBASIC}}===
<langsyntaxhighlight NSlang="ns-HUBASIChubasic">10 FOR 1=10 TO 0 STEP -1
20 PRINT I
30 NEXT</langsyntaxhighlight>
 
==={{header|PureBasic}}===
<langsyntaxhighlight PureBasiclang="purebasic">For i=10 To 0 Step -1
Debug i
Next</langsyntaxhighlight>
 
==={{header|QB64}}===
''CBTJD'': 2020/03/14
<langsyntaxhighlight lang="qbasic">FOR n = 10 TO 0 STEP -1
PRINT n
NEXT</langsyntaxhighlight>
 
==={{header|QBASICQuickBASIC}}===
<langsyntaxhighlight lang="qbasic">for i = 10 to 0 step -1
print i
next i</langsyntaxhighlight>
 
==={{header|Quite BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
<syntaxhighlight lang="lb">for i = 10 to 0 step -1
print i
next i
end</syntaxhighlight>
 
==={{header|TI-83 BASIC}}===
<syntaxhighlight lang="ti83b">:For(I,10,0,-1
<lang ti83b>
:For(I,10,0,-1
:Disp I
:End</syntaxhighlight>
:End
</lang>
 
==={{header|TI-89 BASIC}}===
<langsyntaxhighlight lang="ti89b">Local i
For i, 10, 0, –1
Disp i
EndFor</langsyntaxhighlight>
 
==={{header|True BASIC}}===
{{works with|QBasic}}
<langsyntaxhighlight lang="basic">FOR i = 10 TO 0 STEP -1
PRINT i; " ";
NEXT i
PRINT
END</langsyntaxhighlight>
 
==={{headerHeader|YabasicTiny BASIC}}===
{{works with|QBasicTinyBasic}}
<syntaxhighlight lang="basic">10 REM Loops/Downward for
<lang Yabasic>for i = 10 to 0 step -1
20 LET I = 10
print i, " ";
30 IF I = -1 THEN END
next i
40 PRINT I
print
50 LET I = I - 1
end</lang>
60 GOTO 30
70 END</syntaxhighlight>
 
==={{header|VBA}}===
<syntaxhighlight lang="vb">For i = 10 To 0 Step -1
Debug.Print i
Next i</syntaxhighlight>
 
==={{header|Visual Basic .NET}}===
<syntaxhighlight lang="vbnet">For i = 10 To 0 Step -1
Console.WriteLine(i)
Next</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<langsyntaxhighlight lang="xbasic">PROGRAM "downwardfor"
 
DECLARE FUNCTION Entry()
Line 616 ⟶ 796:
NEXT i%
END FUNCTION
END PROGRAM</langsyntaxhighlight>
 
==={{header|Yabasic}}===
{{works with|QBasic}}
<syntaxhighlight lang="yabasic">for i = 10 to 0 step -1
print i, " ";
next i
print
end</syntaxhighlight>
 
==={{header|ZX Spectrum Basic}}===
<langsyntaxhighlight lang="zxbasic">10 FOR l = 10 TO 0 STEP -1
20 PRINT l
30 NEXT l</langsyntaxhighlight>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">@echo off
for /l %%D in (10,-1,0) do echo %%D</langsyntaxhighlight>
 
=={{header|bc}}==
<langsyntaxhighlight lang="bc">for (i = 10; i >= 0; i--) i
quit</langsyntaxhighlight>
 
=={{header|Befunge}}==
<langsyntaxhighlight lang="befunge">55+>:.:v
@ ^ -1_</langsyntaxhighlight>
 
=={{header|BQN}}==
Line 639 ⟶ 827:
Each (<code>¨</code>) is an operator in BQN that helps with emulating loops like for and foreach.
 
<syntaxhighlight lang ="bqn">•Show¨⌽↕11</langsyntaxhighlight>
 
=={{header|Bracmat}}==
<langsyntaxhighlight lang="bracmat"> 10:?i
& whl'(out$!i&!i+-1:~<0:?i)</langsyntaxhighlight>
 
=={{header|Brainf***}}==
<langsyntaxhighlight lang="brainf***">>++++++++[-<++++++>] //cell 0 now contains 48 the ASCII code for "0"
<+.-. //print the digits 1 and 0
>++++++++++. //cell 1 now contains the carriage return; print it!
Line 652 ⟶ 840:
<<+++++++++>> //cell 0 now contains 57 the ASCII code for "9"
[<<.->.>-] //print and decrement the display digit; print a newline; decrement the loop variable
<<.>. //print the final 0 and a final newline</langsyntaxhighlight>
 
=={{header|Brat}}==
<langsyntaxhighlight lang="brat">10.to 0 { n | p n }</langsyntaxhighlight>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">int i;
for(i = 10; i >= 0; --i)
printf("%d\n",i);</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
 
<langsyntaxhighlight lang="csharp">for (int i = 10; i >= 0; i--)
{
Console.WriteLine(i);
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">for(int i = 10; i >= 0; --i)
std::cout << i << "\n";</langsyntaxhighlight>
 
=={{header|C3}}==
<syntaxhighlight lang="c3">for (int i = 10; i >= 0; i--)
{
io::printn(i);
}</syntaxhighlight>
 
=={{header|Ceylon}}==
<langsyntaxhighlight lang="ceylon">for (i in 10..0) {
print(i);
}</langsyntaxhighlight>
 
=={{header|Chapel}}==
 
<langsyntaxhighlight lang="chapel">for i in 1..10 by -1 do
writeln(i);</langsyntaxhighlight>
 
In case you wonder why it is not written as <tt>10..1 by -1</tt>: <tt>by</tt> is an operator that works on ranges, and it should work the same when the range was defined earlier, like in
 
<langsyntaxhighlight lang="chapel">var r = 1..10;
for i in r by -1 do { ... }</langsyntaxhighlight>
 
=={{header|Clipper}}==
<langsyntaxhighlight lang="clipper"> FOR i := 10 TO 0 STEP -1
? i
NEXT</langsyntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="csharp">(doseq [x (range 10 -1 -1)] (println x))</langsyntaxhighlight>
 
=={{header|COBOL}}==
free-form
<langsyntaxhighlight lang="cobol">identification division.
program-id. countdown.
environment division.
Line 711 ⟶ 905:
display counter-disp
end-perform
stop run.</langsyntaxhighlight>
{{out}}
<pre>10
Line 728 ⟶ 922:
This could be written either in the array comprehension style,
or in "regular" for loop style.
<langsyntaxhighlight lang="coffeescript"># The more compact "array comprehension" style
console.log i for i in [10..0]
 
Line 736 ⟶ 930:
 
# More compact version of the above
for i in [10..0] then console.log i</langsyntaxhighlight>
<pre>10
9
Line 752 ⟶ 946:
=={{header|ColdFusion}}==
With tags:
<langsyntaxhighlight lang="cfm"><cfloop index = "i" from = "10" to = "0" step = "-1">
#i#
</cfloop></langsyntaxhighlight>
With script:
<langsyntaxhighlight lang="cfm"><cfscript>
for( i = 10; i <= 0; i-- )
{
writeOutput( i );
}
</cfscript></langsyntaxhighlight>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(loop for i from 10 downto 1 do
(print i))</langsyntaxhighlight>
 
=== Using DO ===
<langsyntaxhighlight lang="lisp">
(do ((n 10 (decf n))) ; Initialize to 0 and downward in every loop
((< n 0)) ; Break condition when negative
(print n)) ; On every loop print value
</syntaxhighlight>
</lang>
 
=== Using Tagbody and Go ===
<langsyntaxhighlight lang="lisp">
(let ((count 10)) ; Create local variable count = 10
(tagbody
Line 783 ⟶ 977:
(if (not (< count 0)) ; Ends loop when negative
(go dec)))) ; Loops back to tag dec
</syntaxhighlight>
</lang>
 
=== Using Recursion ===
<langsyntaxhighlight lang="lisp">
(defun down-to-0 (count)
(print count)
Line 792 ⟶ 986:
(down-to-0 (1- count))))
(down-to-0 10)
</syntaxhighlight>
</lang>
 
{{out}}
Line 809 ⟶ 1,003:
</pre>
 
=={{header|Computer/zero Assembly}}==
<syntaxhighlight lang="6502asm">LDA 28
SUB 29
STA 31
STA 28
BRZ 6 ;branch on zero to STP
JMP 0
STP
...
org 28
byte 11
byte 1
byte 0</syntaxhighlight>
 
{{out}}[http://www.edmundgriffiths.com/czero.html?hexdump=3c9d5f5ca6c0e00000000000000000000000000000000000000000000b01000a Emulator with program loaded]
=={{header|Crystal}}==
<langsyntaxhighlight lang="crystal">10.step(to: 0, by: -1).each { |i|
puts i
}
</syntaxhighlight>
</lang>
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio: writeln;
 
void main() {
Line 825 ⟶ 1,034:
foreach_reverse (i ; 0 .. 10 + 1)
writeln(i);
}</langsyntaxhighlight>
{{out}}
<pre>10
Line 851 ⟶ 1,060:
0</pre>
 
=={{header|dcDart}}==
<syntaxhighlight lang="dart">void main() {
for (var i = 10; i >= 0; --i) {
print(i);
}
}</syntaxhighlight>
 
=={{header|dc}}==
does not use GNU extensions
 
Line 865 ⟶ 1,080:
uses the macro f - [p] to print, this can be replaced by any complex expressions.
 
<langsyntaxhighlight lang="dc">c
 
[macro s(swap) - (a b : b a)]s.
Line 877 ⟶ 1,092:
 
0 10 ldx [p] sf !<m
q</langsyntaxhighlight>
 
Using it
<langsyntaxhighlight lang="dc">|dc < ./for.dc
10
9
...
0</langsyntaxhighlight>
 
=={{header|Delphi}}==
Line 890 ⟶ 1,105:
 
=={{header|Draco}}==
<langsyntaxhighlight lang="draco">proc nonrec main() void:
byte i;
for i from 10 downto 0 do
write(i," ")
od
corp</langsyntaxhighlight>
{{out}}
<pre>10 9 8 7 6 5 4 3 2 1 0</pre>
 
=={{header|DWScript}}==
<langsyntaxhighlight lang="pascal">for i := 10 downto 0 do
PrintLn(i);</langsyntaxhighlight>
 
=={{header|E}}==
 
<langsyntaxhighlight lang="e">for i in (0..10).descending() { println(i) }</langsyntaxhighlight>
 
=={{header|EasyLang}}==
 
<syntaxhighlight lang="text">for i = 10 downto 0
print i
.</langsyntaxhighlight>
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang="scheme">
(for ((longtemps-je-me-suis-couché-de-bonne-heure (in-range 10 -1 -1)))
(write longtemps-je-me-suis-couché-de-bonne-heure))
→ 10 9 8 7 6 5 4 3 2 1 0
</syntaxhighlight>
</lang>
 
=={{header|EDSAC order code}}==
Including a full routine to print integers in decimal would probably be overkill; at least, it would obscure what is essentially a simple program. We therefore cheat slightly by printing "10\r\n" manually, and using the loop only to print "9\r\n" down to "0\r\n". Note that character codes are stored in the high 5 bits of the 17-bit EDSAC word: so we actually count down from 36,864 to 0 in steps of 4,096.
<langsyntaxhighlight lang="edsac">[ Loop with downward counter
==========================
 
Line 975 ⟶ 1,190:
[ 20 ] OF [ character c = '9' ]
 
EZPF [ start when loaded ]</langsyntaxhighlight>
 
=={{header|EGL}}==
<langsyntaxhighlight EGLlang="egl">for ( i int from 10 to 0 decrement by 1 )
SysLib.writeStdout( i );
end</langsyntaxhighlight>
 
=={{header|Ela}}==
Line 986 ⟶ 1,201:
===Standard Approach===
 
<langsyntaxhighlight lang="ela">open monad io
 
each [] = do return ()
Line 993 ⟶ 1,208:
each xs
 
each [10,9..0] ::: IO</langsyntaxhighlight>
 
===Alternative Approach===
 
<langsyntaxhighlight lang="ela">open monad io
 
countDown m n | n < m = do return ()
Line 1,004 ⟶ 1,219:
countDown m (n - 1)
 
_ = countDown 0 10 ::: IO</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">iex(1)> Enum.each(10..0, fn i -> IO.puts i end)
10
9
Line 1,019 ⟶ 1,234:
1
0
:ok</langsyntaxhighlight>
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">%% Implemented by Arjun Sunel
-module(downward_loop).
-export([main/0]).
Line 1,036 ⟶ 1,251:
io:format("~p~n",[N])
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>10
Line 1,052 ⟶ 1,267:
 
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
<lang ERRE>
FOR I%=10 TO 0 STEP -1 DO
PRINT(I%)
END FOR
</syntaxhighlight>
</lang>
 
=={{header|Euphoria}}==
<langsyntaxhighlight lang="euphoria">for i = 10 to 0 by -1 do
? i
end for</langsyntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Using an enumerable expression:
<langsyntaxhighlight lang="fsharp">for i in 10..-1..0 do
printfn "%d" i</langsyntaxhighlight>
 
Using the 'downto' keyword:
<langsyntaxhighlight lang="fsharp">for i = 10 downto 0 do
printfn "%d" i</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">11 <iota> <reversed> [ . ] each</langsyntaxhighlight>
 
=={{header|FALSE}}==
<langsyntaxhighlight lang="false">10[$0>][$." "1-]#.</langsyntaxhighlight>
 
=={{header|Fantom}}==
 
<langsyntaxhighlight lang="fantom">
class DownwardFor
{
Line 1,091 ⟶ 1,306:
}
}
</syntaxhighlight>
</lang>
 
=={{header|FBSL}}==
<lang qbasic>#APPTYPE CONSOLE
 
FOR DIM i = 10 DOWNTO 0
PRINT i
NEXT
 
PAUSE
</lang>
 
=={{header|Fermat}}==
<langsyntaxhighlight lang="fermat">for i = 10 to 0 by -1 do !!i; od</langsyntaxhighlight>
 
=={{header|Forth}}==
Unlike the incrementing 10 0 DO-LOOP, this will print eleven numbers. The LOOP words detect crossing the floor of the end limit.
<langsyntaxhighlight lang="forth">: loop-down 0 10 do i . -1 +loop ;</langsyntaxhighlight>
 
=={{header|Fortran}}==
{{Works with|Fortran|90 and later}}
<langsyntaxhighlight lang="fortran">DO i = 10, 0, -1
WRITE(*, *) i
END DO</langsyntaxhighlight>
 
{{works with|Fortran|77 and later}}
<langsyntaxhighlight lang="fortran"> PROGRAM DOWNWARDFOR
C Initialize the loop parameters.
INTEGER I, START, FINISH, STEP
Line 1,128 ⟶ 1,333:
 
STOP
END</langsyntaxhighlight>
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">
for i = 10 to 0 step -1
println[i]
</syntaxhighlight>
</lang>
 
=={{header|GAP}}==
<langsyntaxhighlight lang="gap">for i in [10, 9 .. 0] do
Print(i, "\n");
od;</langsyntaxhighlight>
 
=={{header|GML}}==
<langsyntaxhighlight GMLlang="gml">for(i = 10; i >= 0; i -= 1)
show_message(string(i))</langsyntaxhighlight>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">for i := 10; i >= 0; i-- {
fmt.Println(i)
}</langsyntaxhighlight>
::<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 1,162 ⟶ 1,367:
}
fmt.Println("blast off")
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">for (i in (10..0)) {
println i
}</langsyntaxhighlight>
 
=={{header|Harbour}}==
<langsyntaxhighlight lang="visualfoxpro">FOR i := 10 TO 0 STEP -1
? i
NEXT</langsyntaxhighlight>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Control.Monad
 
main :: IO ()
main = forM_ [10,9 .. 0] print</langsyntaxhighlight>
 
=={{header|Haxe}}==
Line 1,184 ⟶ 1,389:
Haxe lacks a downward for-loop, but it is easy to create an iterator to serve that purpose.
 
<langsyntaxhighlight lang="haxe">class Step {
var end:Int;
var step:Int;
Line 1,205 ⟶ 1,410:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,211 ⟶ 1,416:
 
=={{header|hexiscript}}==
<langsyntaxhighlight lang="hexiscript">for let i 10; i >= 0; i--
println i
endfor</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">DO i = 10, 0, -1
WRITE() i
ENDDO</langsyntaxhighlight>
 
=={{header|HolyC}}==
<langsyntaxhighlight lang="holyc">I8 i;
for (i = 10; i >= 0; --i)
Print("%d\n", i);</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
There are four looping controls 'every', 'repeat', 'until', and 'while' (see [[Icon%2BUnicon/Intro#Looping_Controls|Introduction to Icon and Unicon/Looping Controls]] for more information.) The closest to a 'for' loop is 'every'.
<langsyntaxhighlight Iconlang="icon">every i := 10 to 0 by -1 do {
# things to do within the loop
}
</syntaxhighlight>
</lang>
 
=={{header|IDL}}==
Line 1,236 ⟶ 1,441:
Using a loop (with an "increment of minus one" ):
 
<langsyntaxhighlight lang="idl">for i=10,0,-1 do print,i</langsyntaxhighlight>
 
But in IDL one would rarely use loops (for anything) since practically everything can be done with vectors/arrays.
Line 1,242 ⟶ 1,447:
The "IDL way of doing things" for the countdown requested in the task would probably be this:
 
<syntaxhighlight lang ="idl">print,10-indgen(11)</langsyntaxhighlight>
 
=={{header|Inform 6}}==
<langsyntaxhighlight Informlang="inform 6">for(i = 10: i >= 0: i--)
print i, "^";</langsyntaxhighlight>
 
=={{header|Io}}==
<langsyntaxhighlight Iolang="io">for(i,10,0,-1,
i println
)</langsyntaxhighlight>
 
=={{header|J}}==
J is array-oriented, so there is very little need for loops. For example, one could satisfy this task this way:
 
<syntaxhighlight lang=J> ,. i. -11
10
9
8
7
6
5
4
3
2
1
0
</syntaxhighlight>
 
J does support loops for those times they can't be avoided (just like many languages support gotos for those time they can't be avoided).
<langsyntaxhighlight lang="j">3 : 0 ] 11
for_i. i. - y do.
smoutput i
end.
)</langsyntaxhighlight>
 
Though it's rare to see J code like this.
Line 1,269 ⟶ 1,486:
That said, a convenient routine for generating intervals in J might be:
 
<langsyntaxhighlight Jlang="j">thru=: <. + i.@(+*)@-~</langsyntaxhighlight>
 
For example:
 
<langsyntaxhighlight Jlang="j"> 10 thru 0
10 9 8 7 6 5 4 3 2 1 0</langsyntaxhighlight>
 
(or <code>,.10 thru 0</code> if you want each number on a line by itself)
Line 1,281 ⟶ 1,498:
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">
for (int i = 10; i >= 0; i--) {
System.out.println(i);
}
</syntaxhighlight>
</lang>
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">for (var i=10; i>=0; --i) print(i);</langsyntaxhighlight>
 
Alternatively, remaining for the moment within an imperative idiom of JavaScript, in which programs are composed of statements, we could trim the computational costs over longer reversed iterations by moving the mutation into the test, and dropping the third term of a for() statement:
 
<langsyntaxhighlight JavaScriptlang="javascript">for (var i = 11; i--;) console.log(i);</langsyntaxhighlight>
 
and it sometimes might be more natural, especially at scales at which optimisation becomes an issue, to go one step further and express the same computation with the more economical while statement.
 
<langsyntaxhighlight JavaScriptlang="javascript">var i = 11;
while (i--) console.log(i);</langsyntaxhighlight>
 
In a functional idiom of JavaScript, however, we need an expression with a value (which can be composed within superordinate expressions), rather than a statement, which produces a side-effect but returns no information-bearing value.
Line 1,303 ⟶ 1,520:
If we have grown over-attached to the English morpheme 'for', we might think first of turning to '''Array.forEach()''', and write something like:
 
<langsyntaxhighlight JavaScriptlang="javascript">function range(m, n) {
return Array.apply(null, Array(n - m + 1)).map(
function (x, i) {
Line 1,315 ⟶ 1,532:
console.log(x);
}
);</langsyntaxhighlight>
 
 
Line 1,322 ⟶ 1,539:
We can get an expression (assuming that the range() function (above) is defined) but replacing Array.forEach with '''Array.map()'''
 
<langsyntaxhighlight JavaScriptlang="javascript">console.log(
range(0, 10).reverse().map(
function (x) {
Line 1,328 ⟶ 1,545:
}
).join('\n')
);</langsyntaxhighlight>
 
but in this case, we are simply mapping an identity function over the values, so the expression simplifies down to:
 
<langsyntaxhighlight JavaScriptlang="javascript">console.log(
range(0, 10).reverse().join('\n')
);</langsyntaxhighlight>
 
=={{header|jq}}==
If range/3 is available in your jq:
<syntaxhighlight lang ="jq">range(10;-1;-1)</langsyntaxhighlight>
Otherwise:
range(-10;1) | -.
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">for i in 10:-1:0
println(i)
end</langsyntaxhighlight>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">
// version 1.3.61
 
Line 1,354 ⟶ 1,571:
(10 downTo 0).forEach { println(it) }
}
</syntaxhighlight>
</lang>
 
=={{header|Lambdatalk}}==
<langsyntaxhighlight lang="scheme">
{def downward_for
{lambda {:i}
Line 1,367 ⟶ 1,584:
{downward_for 10}
-> 10 9 8 7 6 5 4 3 2 1 0 (end of loop)
</syntaxhighlight>
</lang>
 
=={{header|langur}}==
<syntaxhighlight lang="langur">for .i in 10..0 {
You can use a for in loop to count downward. You cannot use a for of loop for this.
 
<lang langur>for .i in 10..0 {
writeln .i
}</langsyntaxhighlight>
 
<langsyntaxhighlight lang="langur">for .i = 10; .i > -1; .i -= 1 {
writeln .i
}</langsyntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">loop(-from=10, -to=0, -by=-1) => {^ loop_count + ' ' ^}</langsyntaxhighlight>
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">data:
i is number
 
procedure:
for i from 10 to -1 step -1 do
display i lf
repeat</syntaxhighlight>
 
=={{header|Lhogho}}==
Slightly different syntax for <code>for</code> compared to Logo.
<langsyntaxhighlight lang="logo">for "i [10 0] [print :i]</langsyntaxhighlight>
 
=={{header|Lingo}}==
<langsyntaxhighlight lang="lingo">repeat with i = 10 down to 0
put i
end repeat</langsyntaxhighlight>
 
=={{header|Lisaac}}==
<langsyntaxhighlight Lisaaclang="lisaac">10.downto 0 do { i : INTEGER;
i.println;
};</langsyntaxhighlight>
 
=={{header|LiveCode}}==
Livecode's repeat "for" variant does not have a "down to" form, in a function you would need to manually decrement a counter
<langsyntaxhighlight LiveCodelang="livecode">local x=10
repeat for 10 times
put x & return
add -1 to x
end repeat</langsyntaxhighlight>
 
A more idiomatic approach using "with" variant of repeat which does have a "down to" form
<langsyntaxhighlight LiveCodelang="livecode">repeat with n=10 down to 1
put n
end repeat</langsyntaxhighlight>
 
=={{header|Logo}}==
If the limit is less than the start, then FOR decrements the control variable. Otherwise, a fourth parameter could be given as a custom increment.
<langsyntaxhighlight lang="logo">for [i 10 0] [print :i]</langsyntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">
for i=10,0,-1 do
print(i)
end
</syntaxhighlight>
</lang>
 
=={{header|M2000 Interpreter}}==
Line 1,429 ⟶ 1,653:
There is a slower For, the For Next style:
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
For i=1 to 10 step 2 : Print i : Next i
</syntaxhighlight>
</lang>
We have to use Exit For to exit from that type of For.
 
Line 1,441 ⟶ 1,665:
 
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Form 80, 50
Module Checkit {
Line 1,476 ⟶ 1,700:
}
CheckIt
</syntaxhighlight>
</lang>
 
=={{header|M4}}==
<langsyntaxhighlight M4lang="m4">define(`for',
`ifelse($#,0,``$0'',
`ifelse(eval($2 $3),1,
Line 1,485 ⟶ 1,709:
 
for(`x',`10',`>=0',`-1',`x
')</langsyntaxhighlight>
 
=={{header|Maple}}==
Using an explicit loop:
<langsyntaxhighlight Maplelang="maple">for i from 10 to 0 by -1 do print(i) end:</langsyntaxhighlight>
Pushing the loop into the kernel:
<langsyntaxhighlight Maplelang="maple">seq(print(i),i=10..0,-1)</langsyntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Line 1,499 ⟶ 1,723:
 
Using For:
<langsyntaxhighlight Mathematicalang="mathematica">For[i = 10, i >= 0, i--, Print[i]]</langsyntaxhighlight>
Using Do:
<langsyntaxhighlight Mathematicalang="mathematica">Do[Print[i], {i, 10, 0, -1}]</langsyntaxhighlight>
Using Scan:
<langsyntaxhighlight Mathematicalang="mathematica">Scan[Print, Range[10, 0, -1]]</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
 
<langsyntaxhighlight Matlablang="matlab"> for k = 10:-1:0,
printf('%d\n',k)
end; </langsyntaxhighlight>
 
A vectorized version of the code is
 
<langsyntaxhighlight Matlablang="matlab"> printf('%d\n',10:-1:0); </langsyntaxhighlight>
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">for i from 10 thru 0 step -1 do print(i);</langsyntaxhighlight>
 
=={{header|MAXScript}}==
<langsyntaxhighlight lang="maxscript">for i in 10 to 0 by -1 do print i</langsyntaxhighlight>
 
=={{header|Mercury}}==
<syntaxhighlight lang="text">:- module loops_downward_for.
:- interface.
 
Line 1,535 ⟶ 1,759:
io.write_int(I, !IO), io.nl(!IO)
),
int.fold_down(Print, 1, 10, !IO).</langsyntaxhighlight>
 
=={{header|Metafont}}==
 
<langsyntaxhighlight lang="metafont">for i = 10 step -1 until 0: show i; endfor
end</langsyntaxhighlight>
 
The basic set of macros for Metafont defines <tt>downto</tt>, so that we can write
 
<langsyntaxhighlight lang="metafont">for i = 10 downto 0: show i; endfor end</langsyntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.19.6}}
<langsyntaxhighlight lang="min">10 :n (n 0 >=) (n puts! n pred @n) while</langsyntaxhighlight>
Or
<langsyntaxhighlight lang="min">10 (dup 0 <) 'pop (puts pred) () linrec</langsyntaxhighlight>
 
=={{header|MiniScript}}==
<langsyntaxhighlight MiniScriptlang="miniscript">for i in range(10, 0)
print i
end for</langsyntaxhighlight>
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">1 0 П0 ИП0 L0 03 С/П</langsyntaxhighlight>
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE Downward;
IMPORT InOut;
 
Line 1,572 ⟶ 1,796:
InOut.WriteLn
END
END Downward.</langsyntaxhighlight>
 
=={{header|Modula-3}}==
<langsyntaxhighlight lang="modula3">FOR i := 10 TO 0 BY -1 DO
IO.PutInt(i);
END;</langsyntaxhighlight>
 
=={{header|MUMPS}}==
<langsyntaxhighlight MUMPSlang="mumps">LOOPDOWN
NEW I FOR I=10:-1:1 WRITE I WRITE:I'=1 ", "
KILL I QUIT</langsyntaxhighlight>
 
=={{header|N/t/roff}}==
<syntaxhighlight lang="nroff">
.nr a 11 1
.while (\na > 0) \{\
\n-a
.\}
</syntaxhighlight>
{{out}}
<pre>10 9 8 7 6 5 4 3 2 1 0
</pre>
 
=={{header|Nemerle}}==
<langsyntaxhighlight Nemerlelang="nemerle">for (i = 10; i >= 0; i--) {WriteLine($"$i")}</langsyntaxhighlight>
<langsyntaxhighlight Nemerlelang="nemerle">foreach (i in [10, 9 .. 0]) {WriteLine($"$i")}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
Line 1,598 ⟶ 1,833:
say i_.right(2)
end i_
</syntaxhighlight>
</lang>
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">(for (i 10 0)
(println i))</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">for x in countdown(10,0): echo(x)</langsyntaxhighlight>
{{out}}
<pre>10
Line 1,618 ⟶ 1,853:
1
0</pre>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
for i in 10..0 {print $i}
</syntaxhighlight>
 
=={{header|Oberon-2}}==
<langsyntaxhighlight lang="oberon2">FOR i := 10 TO 0 BY -1 DO
Out.Int(i,0);
END;</langsyntaxhighlight>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
for(i := 10; i >= 0; i--;) {
i->PrintLine();
};
</syntaxhighlight>
</lang>
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">for i = 10 downto 0 do
Printf.printf "%d\n" i
done</langsyntaxhighlight>
 
=={{header|Octave}}==
 
<langsyntaxhighlight lang="octave">for i = 10:-1:0
% ...
endfor</langsyntaxhighlight>
 
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">10 0 -1 step: i [ i println ]</langsyntaxhighlight>
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">for I in 10..0;~1 do
{Show I}
end</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">forstep(n=10,0,-1,print(n))</langsyntaxhighlight>
 
=={{header|Pascal}}==
<langsyntaxhighlight lang="pascal">for i := 10 downto 0 do
writeln(i);</langsyntaxhighlight>
 
=={{header|Peloton}}==
English fixed-length opcodes
<langsyntaxhighlight lang="sgml"><@ ITEFORLITLITLITLIT>0|<@ SAYVALFOR>...</@>|10|-1</@></langsyntaxhighlight>
 
Simplified Chinese variable-length opcodes
<langsyntaxhighlight lang="sgml"><# 迭代迭代次数字串字串字串字串>0|<# 显示值迭代次数>...</#>|10|-1</#></langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">foreach (reverse 0..10) {
print "$_\n";
}</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">10</span> <span style="color: #008080;">to</span> <span style="color: #000000;">0</span> <span style="color: #008080;">by</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">i</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: https://rosettacode.org/wiki/Loops/Downward_for
by Galileo, 11/2022 #/
 
include ..\Utilitys.pmt
 
( 10 0 -1 ) for ? endfor</syntaxhighlight>
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php">for ($i = 10; $i >= 0; $i--)
echo "$i\n";</langsyntaxhighlight>
or
<langsyntaxhighlight lang="php">foreach (range(10, 0) as $i)
echo "$i\n";</langsyntaxhighlight>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(for (I 10 (ge0 I) (dec I))
(println I) )</langsyntaxhighlight>
or:
<langsyntaxhighlight PicoLisplang="picolisp">(mapc println (range 10 0))</langsyntaxhighlight>
 
=={{header|Pike}}==
<langsyntaxhighlight lang="pike">int main(){
for(int i = 10; i >= 0; i--){
write(i + "\n");
}
}</langsyntaxhighlight>
 
=={{header|PL/0}}==
<syntaxhighlight lang="pascal">
var i;
begin
i := 10;
while i > -1 do
begin
! i;
i := i - 1
end
end.
</syntaxhighlight>
 
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
do i = 10 to 0 by -1;
put skip list (i);
end;
</syntaxhighlight>
</lang>
 
=={{header|Plain English}}==
One way might be:
<langsyntaxhighlight lang="plainenglish">To run:
Start up.
Put 11 into a counter.
Line 1,721 ⟶ 1,982:
Subtract 1 from the counter.
If the counter is less than the number, say yes.
Say no.</langsyntaxhighlight>
 
=={{header|Pop11}}==
<langsyntaxhighlight lang="pop11">lvars i;
for i from 10 by -1 to 0 do
printf(i, '%p\n');
endfor;</langsyntaxhighlight>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">for ($i = 10; $i -ge 0; $i--) {
$i
}</langsyntaxhighlight>
Alternatively, the range operator might be used as well which simply returns a contiguous range of integers:
<syntaxhighlight lang ="powershell">10..0</langsyntaxhighlight>
 
=={{header|Prolog}}==
Although Prolog has a between(Lo,Hi,Value) iterator, there is no built in equivalent for iterating descending values. This is not a show stopper, as it's easy enough to write one.
<langsyntaxhighlight Prologlang="prolog">rfor(Hi,Lo,Hi) :- Hi >= Lo.
rfor(Hi,Lo,Val) :- Hi > Lo, H is Hi - 1, !, rfor(H,Lo,Val).
 
reverse_iter :-
rfor(10,0,Val), write(Val), nl, fail.
reverse_iter.</langsyntaxhighlight>
<pre>?- reverse_iter.
10
Line 1,760 ⟶ 2,021:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">for i in xrange(10, -1, -1):
print i</langsyntaxhighlight>
 
=== List comprehension ===
 
<langsyntaxhighlight lang="python">[i for i in xrange(10, -1, -1)]</langsyntaxhighlight>
<langsyntaxhighlight lang="python">import pprint
pprint.pprint([i for i in xrange(10, -1, -1)])
</syntaxhighlight>
</lang>
 
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery">11 times [ i echo sp ]</langsyntaxhighlight>
 
{{Out}}
Line 1,779 ⟶ 2,040:
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r">for(i in 10:0) {print(i)}</langsyntaxhighlight>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket
 
(for ([i (in-range 10 -1 -1)])
(displayln i))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 1,793 ⟶ 2,054:
{{works with|Rakudo Star|2010.08}}
 
<syntaxhighlight lang="raku" perl6line>for 10 ... 0 {
.say;
}</langsyntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">for i 10 0 -1 [print i]</langsyntaxhighlight>
 
=={{header|Retro}}==
<syntaxhighlight lang Retro="retro">11 [ putn space ] iterd</langsyntaxhighlight>
 
=={{header|REXX}}==
===version 1===
(equivalent to version 2 and version 3)
<langsyntaxhighlight lang="rexx"> do j=10 to 0 by -1
say j
end</langsyntaxhighlight>
 
===version 2===
(equivalent to version 1 and version 3)
<langsyntaxhighlight lang="rexx"> do j=10 by -1 to 0
say j
end</langsyntaxhighlight>
 
===version 3===
Line 1,820 ⟶ 2,081:
<br><br>Anybody who programs like this should be hunted down and shot like dogs!
<br><br>Hurrumph! Hurrumph!
<langsyntaxhighlight lang="rexx"> do j=10 by -2 to 0
say j
j=j+1 /*this increments the DO index. Do NOT program like this! */
end</langsyntaxhighlight>
 
===version 4===
This example isn't compliant to the task,
but it shows that the increment/decrement can be a non-integer:
<langsyntaxhighlight lang="rexx"> do j=30 to 1 by -.25
say j
end</langsyntaxhighlight>
 
=={{header|Ring}}==
count from 10 to 0 by -1 step:
<langsyntaxhighlight lang="ring">
for i = 10 to 0 step -1 see i + nl next
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
≪ 10 1 '''FOR''' n
n
-1 '''STEP'''
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">10.downto(0) do |i|
puts i
end</langsyntaxhighlight>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">fn main() {
for i in (0..=10).rev() {
println!("{}", i);
}
}</langsyntaxhighlight>
 
=={{header|Salmon}}==
<langsyntaxhighlight Salmonlang="salmon">for (x; 10; x >= 0; -1)
x!;</langsyntaxhighlight>
 
=={{header|Sather}}==
<langsyntaxhighlight lang="sather">class MAIN is
main is
i:INT;
Line 1,862 ⟶ 2,129:
end;
end;
end;</langsyntaxhighlight>
 
=={{header|S-BASIC}}==
<syntaxhighlight lang="BASIC">
var i = integer
for i = 10 to 1 step -1
print i;
next i
 
end
</syntaxhighlight>
{{out}}
<pre>
10 9 8 7 6 5 4 3 2 1
</pre>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">for(i <- 10 to 0 by -1) println(i)
//or
10 to 0 by -1 foreach println</langsyntaxhighlight>
 
=={{header|Scheme}}==
<langsyntaxhighlight lang="scheme">(do ((i 10 (- i 1)))
((< i 0))
(display i)
(newline))</langsyntaxhighlight>
 
=={{header|Scilab}}==
{{works with|Scilab|5.5.1}}
<syntaxhighlight lang="text">for i=10:-1:0
printf("%d\n",i)
end</langsyntaxhighlight>
{{out}}
<pre style="height:20ex">
Line 1,896 ⟶ 2,177:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">for i range 10 downto 0 do
writeln(i);
end for;</langsyntaxhighlight>
 
=={{header|Sidef}}==
'''for(;;)''' loop:
<langsyntaxhighlight lang="ruby">for (var i = 10; i >= 0; i--) {
say i
}</langsyntaxhighlight>
 
'''for-in''' loop:
<langsyntaxhighlight lang="ruby">for i in (11 ^.. 0) {
say i
}</langsyntaxhighlight>
 
'''.each''' method:
<langsyntaxhighlight lang="ruby">10.downto(0).each { |i|
say i
}</langsyntaxhighlight>
 
=={{header|Simula}}==
<langsyntaxhighlight lang="simula">BEGIN
Integer i;
for i := 10 step -1 until 0 do
Line 1,924 ⟶ 2,205:
OutImage
END
END</langsyntaxhighlight>
 
=={{header|Slate}}==
<langsyntaxhighlight lang="slate">10 downTo: 0 do: [| :n | print: n]</langsyntaxhighlight>
 
=={{header|Smalltalk}}==
<langsyntaxhighlight lang="smalltalk">10 to: 0 by: -1 do:[:aNumber |
aNumber displayNl.
].
Line 1,936 ⟶ 2,217:
10 downTo: 0 do:[:eachNumber |
eachNumber displayNl.
]</langsyntaxhighlight>
Both enumerate 10 to 0 inclusive.
 
Non-Smalltalkers might be confused when seeing:
<langsyntaxhighlight lang="smalltalk">(10 to: 0 by: -1) do:[:eachNumber |
eachNumber displayNl.
]</langsyntaxhighlight>
which has the same effect, but a slightly different mechanism.
 
Line 1,952 ⟶ 2,233:
 
The nice thing with Intervals is that they can be concatenated with a <tt>","</tt> operator (like all collections); thus, I could also write:
<langsyntaxhighlight lang="smalltalk">(10 to: 5 by: -1),(0 to: 4) do:[:eachNumber |
eachNumber displayNl.
]</langsyntaxhighlight>
to enumerate in a different order,
<br>or combine ranges with a constant array:
<langsyntaxhighlight lang="smalltalk">(10 to: 0 by: -2),#(99 999),(1 to: 9 by: 2) do:[:each |
each displayNl.
]</langsyntaxhighlight>
or with a computed array:
<langsyntaxhighlight lang="smalltalk">(10 to: 0 by: -2),{ 10 factorial . 11 factorial},(1 to: 9 by: 2) do:[:each |
each displayNl.
]</langsyntaxhighlight>
 
PS: there is also a reverse do, as in:
<langsyntaxhighlight lang="smalltalk">(0 to:10) reverseDo:[:each |
each displayNl.
]</langsyntaxhighlight>
 
=={{header|SNOBOL4}}==
<langsyntaxhighlight lang="snobol4"> COUNT = 10
LOOP OUTPUT = COUNT
COUNT = COUNT - 1
GE(COUNT, 0) :S(LOOP)
END</langsyntaxhighlight>
 
=={{header|SNUSP}}==
<langsyntaxhighlight lang="snusp">++++++++++>++++++++++!/- @!\=@\.@@@-@-----# atoi
\n counter #\?>.</ \ @@@+@+++++# itoa
loop</langsyntaxhighlight>
 
=={{header|Sparkling}}==
<langsyntaxhighlight lang="sparkling">for var i = 10; i >= 0; i-- {
print(i);
}</langsyntaxhighlight>
 
=={{header|Spin}}==
Line 1,992 ⟶ 2,273:
{{works with|HomeSpun}}
{{works with|OpenSpin}}
<langsyntaxhighlight lang="spin">con
_clkmode = xtal1 + pll16x
_clkfreq = 80_000_000
Line 2,008 ⟶ 2,289:
waitcnt(_clkfreq + cnt)
ser.stop
cogstop(0)</langsyntaxhighlight>
{{out}}
<pre>10 9 8 7 6 5 4 3 2 1 0</pre>
 
=={{header|SPL}}==
<langsyntaxhighlight lang="spl">> i, 10..0,-1
#.output(i)
<</langsyntaxhighlight>
 
=={{header|SSEM}}==
The SSEM can't print, so the results are stored in an array at addresses 22 to 31. Array access is done using self-modifying code: on each iteration we subtract the current value of <tt>n</tt> (stored at address 18) from the illegal instruction <tt>c to 32</tt>, yielding the actual instruction we use to store <tt>n</tt> into the array.
<langsyntaxhighlight lang="ssem">10001000000000100000000000000000 0. -17 to c
11001000000001100000000000000000 1. c to 19
11001000000000100000000000000000 2. -19 to c
Line 2,037 ⟶ 2,318:
11111111111111111111111111111111 16. -1
00000100000001100000000000000000 17. c to 32
01010000000000000000000000000000 18. 10</langsyntaxhighlight>
 
=={{header|Stata}}==
See '''[https://www.stata.com/help.cgi?forvalues forvalues]''' and '''[https://www.stata.com/help.cgi?foreach foreach]''' in Stata help.
 
<langsyntaxhighlight lang="stata">forvalues n=10(-1)0 {
display `n'
}
Line 2,052 ⟶ 2,333:
foreach n of numlist 10/0 {
display `n'
}</langsyntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">for i in stride(from: 10, through: 0, by: -1) {
println(i)
}</langsyntaxhighlight>
Alternately:
<langsyntaxhighlight lang="swift">for i in lazy(0...10).reverse() {
println(i)
}</langsyntaxhighlight>
In Swift 1.2 Alternately:
<langsyntaxhighlight lang="swift">for i in reverse(0 ... 10) {
println(i)
}</langsyntaxhighlight>
Alternately (removed in Swift 3):
<langsyntaxhighlight lang="swift">for var i = 10; i >= 0; i-- {
println(i)
}</langsyntaxhighlight>
Swift 3:
<langsyntaxhighlight lang="swift">for i in (0...10).reversed() {
print(i)
}</langsyntaxhighlight>
 
=={{header|Tailspin}}==
Not really a for-loop, but it sends a stream of values where each gets treated the same way.
<langsyntaxhighlight lang="tailspin">
10..0:-1 -> '$;
' -> !OUT::write
</syntaxhighlight>
</lang>
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">for {set i 10} {$i >= 0} {incr i -1} {
puts $i
}
# puts "We have liftoff!"</langsyntaxhighlight>
 
=={{header|Trith}}==
<langsyntaxhighlight lang="trith">10 inc iota reverse [print] each</langsyntaxhighlight>
<langsyntaxhighlight lang="trith">10 [dup print dec] [dup 0 >=] while drop</langsyntaxhighlight>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
LOOP n=10,0,-1
PRINT n
ENDLOOP
</syntaxhighlight>
</lang>
 
=={{header|UNIX Shell}}==
{{works with|Bourne Shell}}
<langsyntaxhighlight lang="bash">i=10
while test $i -ge 0; do
echo $i
Line 2,114 ⟶ 2,395:
# or
 
seq 10 -1 0</langsyntaxhighlight>
 
----
{{works with|bash}}
<langsyntaxhighlight lang="bash">for(( Z=10; Z>=0; Z-- )); do
echo $Z
done
Line 2,127 ⟶ 2,408:
echo $Z
done
</syntaxhighlight>
</lang>
 
=={{header|UnixPipes}}==
{{works with|OpenBSD|4.9}}
<langsyntaxhighlight lang="bash">yes '' | cat -n | head -n 11 | while read n; do
expr $n - 1
done | tail -r</langsyntaxhighlight>
 
This pipe uses several nonstandard commands: <code>cat -n</code> and <code>tail -r</code> might not work with some systems.
Line 2,139 ⟶ 2,420:
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa">decl int i
for (set i 10) (> i -1) (dec i)
out i endl console
end for</langsyntaxhighlight>
 
=={{header|V}}==
<langsyntaxhighlight lang="v">10
[0 >]
[dup puts pred]
while</langsyntaxhighlight>
 
=={{header|Vala}}==
<langsyntaxhighlight lang="vala">for (int i = 10; i >= 0; --i)
stdout.printf("%d\n", i);</langsyntaxhighlight>
 
=={{header|VBA}}==
<lang VB>For i = 10 To 0 Step -1
Debug.Print i
Next i</lang>
 
=={{header|Vedit macro language}}==
<langsyntaxhighlight lang="vedit">for (#1 = 10; #1 >= 0; #1--) {
Num_Type(#1)
}</langsyntaxhighlight>
 
=={{header|Verilog}}==
<syntaxhighlight lang="verilog">
<lang Verilog>
module main;
integer i;
Line 2,175 ⟶ 2,451:
end
endmodule
</syntaxhighlight>
</lang>
 
=={{header|VisualV Basic .NET(Vlang)}}==
<syntaxhighlight lang="v (vlang)">fn main() {
<lang vbnet>For i = 10 To 0 Step -1
Console.WriteLine(i)
Next</lang>
 
=={{header|Vlang}}==
<lang vlang>fn main() {
for i := 10; i >= 0; i-- {
print('$i ')
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,195 ⟶ 2,466:
 
=={{header|Wart}}==
<syntaxhighlight lang="text">for i 10 (i >= 0) --i
prn i</langsyntaxhighlight>
 
=={{header|Wren}}==
<langsyntaxhighlight ecmascriptlang="wren">for (i in 10..0) System.write("%(i) ")
System.print()</langsyntaxhighlight>
 
{{out}}
Line 2,208 ⟶ 2,479:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes; \intrinsic 'code' declarations
int I;
for I:= 10 downto 0 do
[IntOut(0, I); CrLf(0)]</langsyntaxhighlight>
 
=={{header|Z80 Assembly}}==
Because of the way looping typically works in hardware, as well as 10 being two digits, it's more efficient to only print numbers 9 through 1 in the loop body, and do the rest outside it.
<syntaxhighlight lang="z80">org &1000
 
LD A,'1'
CALL &BB5A
LD A,'0'
CALL &BB5A
 
LD B,9
LD A,'9'
 
for:
CALL &BB5A
DEC A
DJNZ for
 
LD A,'0'
JP &BB5A ;its RET returns to BASIC for us.</syntaxhighlight>
 
{{out}}
<pre>Amstrad Microcomputer (v4)
(c) 1985 Amstrad plc
and Locomotive Software Ltd.
ParaDOS V1.2+ (c)2015 BitWise Systems.
 
BASIC 1.1
Ready
call &1000
109876543210
Ready</pre>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">foreach n in ([10..0,-1]){ println(n) }
[10..0,-1].apply() //-->L(10,9,8,7,6,5,4,3,2,1,0)
// tail recursion
fcn(n){ n.println(); if(n==0)return(); return(self.fcn(n-1)) }(10)</langsyntaxhighlight>
 
=={{header|Zig}}==
<syntaxhighlight lang="zig">const std = @import("std");
 
pub fn main() !void {
var i: u8 = 11;
while (i > 0) {
i -= 1;
try std.io.getStdOut().writer().print("{d}\n", .{i});
}
}</syntaxhighlight>
13

edits