CloudFlare suffered a massive security issue affecting all of its customers, including Rosetta Code. All passwords not changed since February 19th 2017 have been expired, and session cookie longevity will be reduced until late March.--Michael Mol (talk) 05:15, 25 February 2017 (UTC)

Loops/Downward for

From Rosetta Code
Task
Loops/Downward for
You are encouraged to solve this task according to the task description, using any language you may know.
Task

Write a   for   loop which writes a countdown from   10   to   0.

Contents

360 Assembly[edit]

Use of BXLE and BCT opcodes.

*        Loops/Downward for        27/07/2015
LOOPDOWN CSECT
USING LOOPDOWN,R12
LR R12,R15 set base register
BEGIN EQU *
* fisrt loop with a BXLE BXLE: Branch on indeX Low or Equal
LH R2,=H'11' from 10 (R2=11) index
LH R4,=H'-1' step -1 (R4=-1)
LH R5,=H'-1' to 0 (R5=-1)
LOOPI BXLE R2,R4,ELOOPI R2=R2+R4 if R2<=R5 goto ELOOPI
XDECO R2,BUFFER edit R2
XPRNT BUFFER,L'BUFFER print
B LOOPI
ELOOPI EQU *
* second loop with a BCT BCT: Branch on CounT
LA R2,10 index R2=10
LA R3,11 counter R3=11
LOOPJ XDECO R2,BUFFER edit R2
XPRNT BUFFER,L'BUFFER print
BCTR R2,0 R2=R2-1
ELOOPJ BCT R3,LOOPJ R3=R3-1 if R3<>0 goto LOOPI
RETURN XR R15,R15 set return code
BR R14 return to caller
BUFFER DC CL80' '
YREGS
END LOOPDOWN

6502 Assembly[edit]

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.

;An OS/hardware specific routine that is setup to display the Ascii character
;value contained in the Accumulator
Send = $9000 ;routine not implemented here
PrintNewLine = $9050 ;routine not implemented here
 
*= $8000 ;set base address
Start PHA ;push Accumulator and Y register onto stack
TYA
PHA
LDY #10 ;set Y register to loop start value
TYA ;place loop value in the Accumulator
Loop JSR PrintTwoDigits
JSR PrintNewLine
DEY ;decrement loop value
BPL Loop ;continue loop if sign flag is clear
PLA ;pop Y register and Accumulator off of stack
TAY
PLA
RTS ;exit
 
;Print value in Accumulator as two hex digits
PrintTwoDigits
PHA
LSR
LSR
LSR
LSR
JSR PrintDigit
PLA
AND #$0F
JSR PrintDigit
RTS
 
;Convert value in Accumulator to an Ascii hex digit
PrintDigit
ORA #$30
JSR Send ;routine not implemented here
RTS

Ada[edit]

for I in reverse 0..10 loop
Put_Line(Integer'Image(I));
end loop;

Agena[edit]

Tested with Agena 2.9.5 Win32

for i from 10 downto 0 do
print( i )
od

ALGOL 68[edit]

Works with: ALGOL 68 version Standard - no extensions to language used
Works with: ALGOL 68G version Any - tested with release mk15-0.8b.fc9.i386
Works with: ELLA ALGOL 68 version Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386
FOR i FROM 10 BY -1 TO 0 DO
print((i,new line))
OD

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.

FOR i FROM 10 DOWNTO 0 DO
print((i,new line))
OD

ALGOL W[edit]

begin
for i := 10 step -1 until 0 do
begin
write( i )
end
end.

AmigaE[edit]

PROC main()
DEF i
FOR i := 10 TO 0 STEP -1
WriteF('\d\n', i)
ENDFOR
ENDPROC

AppleScript[edit]

repeat with i from 10 to 0 by -1
log i
end repeat

AutoHotkey[edit]

x := 10
While (x >= 0)
{
output .= "`n" . x
x--
}
MsgBox % output
 

AWK[edit]

BEGIN {
for(i=10; i>=0; i--) {
print i
}
}

Axe[edit]

Axe does not support for loops with step sizes other than 1.

For(I,0,10)
Disp 10-I▶Dec,i
End

BASIC[edit]

FOR i = 10 TO 0 STEP -1
PRINT i
NEXT i

Applesoft BASIC[edit]

FOR I = 10 TO 0 STEP -1 : PRINT I : NEXT I

BaCon[edit]

' Downward for
FOR i = 10 DOWNTO 0 : PRINT i : NEXT

Commodore BASIC[edit]

10 FOR I = 10 TO 0 STEP -1
20 PRINT I
30 NEXT

Batch File[edit]

@echo off
for /l %%D in (10,-1,0) do echo %%D

BBC BASIC[edit]

      FOR i% = 10 TO 0 STEP -1
PRINT i%
NEXT

bc[edit]

for (i = 10; i >= 0; i--) i
quit

Befunge[edit]

55+>:.:v
@ ^ -1_

Bracmat[edit]

  10:?i
& whl'(out$!i&!i+-1:~<0:?i)

Brat[edit]

10.to 0 { n | p n }

C[edit]

int i;
for(i = 10; i >= 0; --i)
printf("%d\n",i);

C++[edit]

for(int i = 10; i >= 0; --i)
std::cout << i << "\n";

C#[edit]

for (int i = 10; i >= 0; i--)
{
Console.WriteLine(i);
}

Ceylon[edit]

for (i in 10..0) {
print(i);
}

Clojure[edit]

(doseq [x (range 10 -1 -1)] (println x))

COBOL[edit]

free-form

identification division.
program-id. countdown.
environment division.
data division.
working-storage section.
01 counter pic 99.
88 counter-done value 0.
01 counter-disp pic Z9.
procedure division.
perform with test after varying counter from 10 by -1 until counter-done
move counter to counter-disp
display counter-disp
end-perform
stop run.
Output:
10
 9
 8
 7
 6
 5
 4
 3
 2
 1
 0

CoffeeScript[edit]

This could be written either in the array comprehension style, or in "regular" for loop style.

# The more compact "array comprehension" style
console.log i for i in [10..0]
 
# The "regular" for loop style.
for i in [10..0]
console.log i
 
# More compact version of the above
for i in [10..0] then console.log i
10
9
8
7
6
5
4
3
2
1
0

(the output is repeated three times; once for each loop)

ColdFusion[edit]

With tags:

<cfloop index = "i" from = "10" to = "0" step = "-1">
#i#
</cfloop>

With script:

<cfscript>
for( i = 10; i <= 0; i-- )
{
writeOutput( i );
}
</cfscript>

Common Lisp[edit]

(loop for i from 10 downto 1 do
(print i))

Chapel[edit]

for i in 1..10 by -1 do
writeln(i);

In case you wonder why it is not written as 10..1 by -1: by is an operator that works on ranges, and it should work the same when the range was defined earlier, like in

var r = 1..10;
for i in r by -1 do { ... }

Clipper[edit]

   FOR i := 10 TO 0 STEP -1
 ? i
NEXT

D[edit]

import std.stdio: writeln;
 
void main() {
for (int i = 10; i >= 0; --i)
writeln(i);
writeln();
 
foreach_reverse (i ; 0 .. 10 + 1)
writeln(i);
}
Output:
10
9
8
7
6
5
4
3
2
1
0

10
9
8
7
6
5
4
3
2
1
0

dc[edit]

does not use GNU extensions

[]s. is a comment

c clears the stack

[~...]p s. to print strings

l<register>x executes the macro

uses the macro f - [p] to print, this can be replaced by any complex expressions.

c
 
[macro s(swap) - (a b : b a)]s.
[Sa Sb La Lb] ss
 
[macro d(2dup) - (a b : a b a b)]s.
[Sa d Sb La d Lb lsx] sd
 
[macro m(for) - ]s.
[lfx 1 - ldx !<m ] sm
 
0 10 ldx [p] sf !<m
q

Using it

|dc < ./for.dc
10
9
...
0

Delphi[edit]

See Pascal

DWScript[edit]

for i := 10 downto 0 do
PrintLn(i);

E[edit]

for i in (0..10).descending() { println(i) }

EchoLisp[edit]

 
(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
 

EDSAC order code[edit]

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.

[ Loop with downward counter
==========================
 
A program for the EDSAC
 
Prints the integers 10 down to 0
 
The counter is stored at address 20@
 
Its initial value is 9 * 2^12
(9 in the high 5 bits, representing
the character '9') and it counts
down in steps of 2^12
 
Works with Initial Orders 2 ]
 
T56K [ set load point ]
GK [ set base address ]
 
[ orders ]
 
O14@ [ print figure shift ]
O15@ [ print '1' ]
O16@ [ print '0' ]
O17@ [ print CR ]
O18@ [ print LF ]
 
[ 5 ] O20@ [ print c ]
O17@ [ print CR ]
O18@ [ print LF ]
 
T19@ [ acc := 0 ]
A20@ [ acc += c ]
S15@ [ acc -:= character '1' ]
U20@ [ c := acc ]
 
E5@ [ branch on non-negative ]
 
ZF [ stop ]
 
[ constants ]
 
[ 14 ] #F [ πF -- figure shift ]
[ 15 ] QF [ character '1' ]
[ 16 ] PF [ character '0' ]
[ 17 ] @F [ θF -- CR ]
[ 18 ] &F [ ΔF -- LF ]
 
[ variables ]
 
[ 19 ] P0F [ used to clear acc ]
[ 20 ] OF [ character c = '9' ]
 
EZPF [ start when loaded ]

EGL[edit]

for ( i int from 10 to 0 decrement by 1 )
SysLib.writeStdout( i );
end

Elixir[edit]

iex(1)> Enum.each(10..0, fn i -> IO.puts i end)
10
9
8
7
6
5
4
3
2
1
0
:ok

Erlang[edit]

%% Implemented by Arjun Sunel
-module(downward_loop).
-export([main/0]).
 
main() ->
for_loop(10).
 
for_loop(N) ->
if N > 0 ->
io:format("~p~n",[N] ),
for_loop(N-1);
true ->
io:format("~p~n",[N])
end.
 
Output:
10
9
8
7
6
5
4
3
2
1
0
ok

ERRE[edit]

 
FOR I%=10 TO 0 STEP -1 DO
PRINT(I%)
END FOR
 

Euphoria[edit]

for i = 10 to 0 by -1 do
? i
end for

Ela[edit]

Standard Approach[edit]

open monad io
 
each [] = do return ()
each (x::xs) = do
putStrLn $ show x
each xs
 
each [10,9..0] ::: IO

Alternative Approach[edit]

open monad io
 
countDown m n | n < m = do return ()
| else = do
putStrLn $ show n
countDown m (n - 1)
 
_ = countDown 0 10 ::: IO

Factor[edit]

11 iota <reversed> [ . ] each

FALSE[edit]

10[$0>][$." "1-]#.

Fantom[edit]

 
class DownwardFor
{
public static Void main ()
{
for (Int i := 10; i >= 0; i--)
{
echo (i)
}
}
}
 

FBSL[edit]

#APPTYPE CONSOLE
 
FOR DIM i = 10 DOWNTO 0
PRINT i
NEXT
 
PAUSE
 

Forth[edit]

Unlike the incrementing 10 0 DO-LOOP, this will print eleven numbers. The LOOP words detect crossing the floor of the end limit.

: loop-down  0 10 do  i .  -1 +loop ;

Fortran[edit]

Works with: Fortran version 90 and later
DO i = 10, 0, -1
WRITE(*, *) i
END DO
Works with: Fortran version 77 and later
      PROGRAM DOWNWARDFOR
C Initialize the loop parameters.
INTEGER I, START, FINISH, STEP
PARAMETER (START = 10, FINISH = 0, STEP = -1)
 
C If you were to leave off STEP, it would default to positive one.
DO 10 I = START, FINISH, STEP
WRITE (*,*) I
10 CONTINUE
 
STOP
END

FreeBASIC[edit]

' FB 1.05.0 Win64
 
For i As Integer = 10 To 0 Step -1
Print i; " ";
Next
Print
Sleep
Output:
 10  9  8  7  6  5  4  3  2  1  0

Frink[edit]

 
for i = 10 to 0 step -1
println[i]
 

F#[edit]

Using an enumerable expression:

for i in 10..-1..0 do
printfn "%d" i

Using the 'downto' keyword:

for i = 10 downto 0 do
printfn "%d" i

FutureBasic[edit]

 
include "ConsoleWindow"
 
dim as long i
 
for i = 10 to 0 step -1
print i
next
 

Output:

 10
 9
 8
 7
 6
 5
 4
 3
 2
 1
 0

GAP[edit]

for i in [10, 9 .. 0] do
Print(i, "\n");
od;

GML[edit]

for(i = 10; i >= 0; i -= 1)
show_message(string(i))

Go[edit]

for i := 10; i >= 0; i-- {
fmt.Println(i)
}

Groovy[edit]

for (i in (10..0)) {
println i
}

Harbour[edit]

FOR i := 10 TO 0 STEP -1
? i
NEXT

Haskell[edit]

import Control.Monad
 
main :: IO ()
main = forM_ [10,9 .. 0] print

HicEst[edit]

DO i = 10, 0, -1
WRITE() i
ENDDO

IDL[edit]

Using a loop (with an "increment of minus one" ):

for i=10,0,-1 do print,i

But in IDL one would rarely use loops (for anything) since practically everything can be done with vectors/arrays.

The "IDL way of doing things" for the countdown requested in the task would probably be this:

print,10-indgen(11)

Icon and Unicon[edit]

There are four looping controls 'every', 'repeat', 'until', and 'while' (see Introduction to Icon and Unicon/Looping Controls for more information.) The closest to a 'for' loop is 'every'.

every i := 10 to 0 by -1 do {
# things to do within the loop
}
 

Inform 6[edit]

for(i = 10: i >= 0: i--)
print i, "^";

Io[edit]

for(i,10,0,-1,
i println
)

J[edit]

J is array-oriented, so there is very little need for loops. For example, one could satisfy this task this way:

  ,. i. -11

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).

3 : 0 ] 11
for_i. i. - y do.
smoutput i
end.
)

Though it's rare to see J code like this.

That said, a convenient routine for generating intervals in J might be:

thru=: <. + i.@(+*)@-~

For example:

   10 thru 0
10 9 8 7 6 5 4 3 2 1 0

(or ,.10 thru 0 if you want each number on a line by itself)

This verb "thru" will count up or down, starting and stop at the indicated left and right ending points.

Java[edit]

for(i = 10; i >= 0; --i){
System.out.println(i);
}

JavaScript[edit]

for (var i=10; i>=0; --i) print(i);

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:

for (var i = 11; i--;) console.log(i);

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.

var i = 11;
while (i--) console.log(i);

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.

If we have grown over-attached to the English morpheme 'for', we might think first of turning to Array.forEach(), and write something like:

function range(m, n) {
return Array.apply(null, Array(n - m + 1)).map(
function (x, i) {
return m + i;
}
);
}
 
range(0, 10).reverse().forEach(
function (x) {
console.log(x);
}
);


but this is still a statement with side-effects, rather than a composable expression with a value.

We can get an expression (assuming that the range() function (above) is defined) but replacing Array.forEach with Array.map()

console.log(
range(0, 10).reverse().map(
function (x) {
return x;
}
).join('\n')
);

but in this case, we are simply mapping an identity function over the values, so the expression simplifies down to:

console.log(
range(0, 10).reverse().join('\n')
);

jq[edit]

If range/3 is available in your jq:

range(10;-1;-1)

Otherwise:

range(-10;1) | -.

Julia[edit]

for i in 10:-1:0
println(i)
end

Kotlin[edit]

// version 1.0.6
 
fun main(args: Array<String>) {
for (i in 10 downTo 0) print("$i ")
}
Output:
10 9 8 7 6 5 4 3 2 1 0

Lasso[edit]

loop(-from=10, -to=0, -by=-1) => {^ loop_count + ' ' ^}

Lhogho[edit]

Slightly different syntax for for compared to Logo.

for "i [10 0] [print :i]

Liberty BASIC[edit]

 
for i = 10 to 0 step -1
print i
next i
end
 

Lingo[edit]

repeat with i = 10 down to 0
put i
end repeat

Lisaac[edit]

10.downto 0 do { i : INTEGER;
i.println;
 
};

LiveCode[edit]

Livecode's repeat "for" variant does not have a "down to" form, in a function you would need to manually decrement a counter

local x=10
repeat for 10 times
put x & return
add -1 to x
end repeat

A more idiomatic approach using "with" variant of repeat which does have a "down to" form

repeat with n=10 down to 1
put n
end repeat

[edit]

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.

for [i 10 0] [print :i]

Lua[edit]

 
for i=10,0,-1 do
print(i)
end
 

M4[edit]

define(`for',
`ifelse($#,0,``$0'',
`ifelse(eval($2 $3),1,
`pushdef(`$1',$2)$5`'popdef(`$1')$0(`$1',eval($2+$4),$3,$4,`$5')')')')dnl
 
for(`x',`10',`>=0',`-1',`x
')

Maple[edit]

Using an explicit loop:

for i from 10 to 0 by -1 do print(i) end:

Pushing the loop into the kernel:

seq(print(i),i=10..0,-1)

Mathematica[edit]

Mathematica provides several ways to iterate over a range of numbers, small subtle differences are amongst them. 3 possible implementations are (exactly the same output):

Using For:

For[i = 10, i >= 0, i--, Print[i]]

Using Do:

Do[Print[i], {i, 10, 0, -1}]

Using Scan:

Scan[Print, Range[10, 0, -1]]

MATLAB / Octave[edit]

    for k = 10:-1:0,
printf('%d\n',k)
end;

A vectorized version of the code is

  printf('%d\n',10:-1:0);  

Maxima[edit]

for i from 10 thru 0 step -1 do print(i);

MAXScript[edit]

for i in 10 to 0 by -1 do print i

Mercury[edit]

:- module loops_downward_for.
:- interface.
 
:- import_module io.
:- pred main(io::di, io::uo) is det.
 
:- implementation.
:- import_module int.
 
main(!IO) :-
Print = (pred(I::in, !.IO::di, !:IO::uo) is det :-
io.write_int(I, !IO), io.nl(!IO)
),
int.fold_down(Print, 1, 10, !IO).

Metafont[edit]

for i = 10 step -1 until 0: show i; endfor
end

The basic set of macros for Metafont defines downto, so that we can write

for i = 10 downto 0: show i; endfor end

МК-61/52[edit]

1	0	П0	ИП0	L0	03	С/П

Modula-2[edit]

MODULE Downward;
IMPORT InOut;
 
VAR
i: INTEGER;
 
BEGIN
FOR i := 10 TO 0 BY -1 DO
InOut.WriteInt(i, 2);
InOut.WriteLn
END
END Downward.

Modula-3[edit]

FOR i := 10 TO 0 BY -1 DO
IO.PutInt(i);
END;

MUMPS[edit]

LOOPDOWN
NEW I FOR I=10:-1:1 WRITE I WRITE:I'=1 ", "
KILL I QUIT

NewLISP[edit]

(for (i 10 0)
(println i))

Nim[edit]

for x in countdown(10,0): echo(x)
Output:
10
9
8
7
6
5
4
3
2
1
0

Nemerle[edit]

for (i = 10; i >= 0; i--) {WriteLine($"$i")}
foreach (i in [10, 9 .. 0]) {WriteLine($"$i")}

NetRexx[edit]

/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
say
say 'Loops/Downward for'
 
loop i_ = 10 to 0 by -1
say i_.right(2)
end i_
 

Oberon-2[edit]

FOR i := 10 TO 0 BY -1 DO
Out.Int(i,0);
END;

Objeck[edit]

 
for(i := 10; i >= 0; i--;) {
i->PrintLine();
};
 

OCaml[edit]

for i = 10 downto 0 do
Printf.printf "%d\n" i
done

Octave[edit]

for i = 10:-1:0
% ...
endfor

Oforth[edit]

10 0 -1 step: i [ i println ]

Oz[edit]

for I in 10..0;~1 do
{Show I}
end

PARI/GP[edit]

forstep(n=10,0,-1,print(n))

Pascal[edit]

for i := 10 downto 0 do
writeln(i);

Peloton[edit]

English fixed-length opcodes

<@ ITEFORLITLITLITLIT>0|<@ SAYVALFOR>...</@>|10|-1</@>

Simplified Chinese variable-length opcodes

<# 迭代迭代次数字串字串字串字串>0|<# 显示值迭代次数>...</#>|10|-1</#>

Perl[edit]

foreach (reverse 0..10) {
print "$_\n";
}

Perl 6[edit]

Works with: Rakudo Star version 2010.08
for 10 ... 0 {
.say;
}

Phix[edit]

for i=10 to 0 by -1 do
 ?i
end for

PHP[edit]

for ($i = 10; $i >= 0; $i--)
echo "$i\n";

or

foreach (range(10, 0) as $i)
echo "$i\n";

PicoLisp[edit]

(for (I 10 (ge0 I) (dec I))
(println I) )

or:

(mapc println (range 10 0))

Pike[edit]

int main(){
for(int i = 10; i >= 0; i--){
write(i + "\n");
}
}

PL/I[edit]

 
do i = 10 to 0 by -1;
put skip list (i);
end;
 

Pop11[edit]

lvars i;
for i from 10 by -1 to 0 do
printf(i, '%p\n');
endfor;

PowerShell[edit]

for ($i = 10; $i -ge 0; $i--) {
$i
}

Alternatively, the range operator might be used as well which simply returns a contiguous range of integers:

10..0

PureBasic[edit]

For i=10 To 0 Step -1
Debug i
Next

Python[edit]

for i in xrange(10, -1, -1):
print i

List comprehension[edit]

[i for i in xrange(10, -1, -1)]
import pprint
pprint.pprint([i for i in xrange(10, -1, -1)])
 

R[edit]

for(i in 10:0) {print(i)}

Racket[edit]

 
#lang racket
 
(for ([i (in-range 10 -1 -1)])
(displayln i))
 

REBOL[edit]

for i 10 0 -1 [print i]

Retro[edit]

11 [ putn space ] iterd

REXX[edit]

version 1[edit]

(equivalent to version 2 and version 3)

  do j=10  to 0  by -1
say j
end

version 2[edit]

(equivalent to version 1 and version 3)

  do j=10  by -1  to 0
say j
end

version 3[edit]

(equivalent to version 1 and version 2)

Anybody who programs like this should be hunted down and shot like dogs!

Hurrumph! Hurrumph!

  do j=10  by -2  to 0
say j
j=j+1 /*this increments the DO index. Do NOT program like this! */
end

version 4[edit]

This example isn't compliant to the task, but it shows that the increment/decrement can be a non-integer:

  do j=30  to 1  by -.25
say j
end

Ring[edit]

count from 10 to 0 by -1 step:

 
for i = 10 to 0 step -1 see i + nl next
 

Ruby[edit]

10.downto(0) do |i|
puts i
end

Rust[edit]

fn main() {
for i in (1..10+1).rev() {
println!("{}", i);
}
}

Salmon[edit]

for (x; 10; x >= 0; -1)
x!;

Sather[edit]

class MAIN is
main is
i:INT;
loop i := 10.downto!(0);
#OUT + i + "\n";
end;
end;
end;

Scala[edit]

for(i <- 10 to 0 by -1) println(i)
//or
10 to 0 by -1 foreach println

Scheme[edit]

(do ((i 10 (- i 1)))
((< i 0))
(display i)
(newline))

Seed7[edit]

for i range 10 downto 0 do
writeln(i);
end for;

Scilab[edit]

Works with: Scilab version 5.5.1
for i=10:-1:0
printf("%d\n",i)
end
Output:
10
9
8
7
6
5
4
3
2
1
0

Sidef[edit]

for(;;) loop:

for (var i = 10; i >= 0; i--) {
say i
}

for-in loop:

for i in (11 ^.. 0) {
say i
}

.each method:

10.downto(0).each { |i|
say i
}

Simula[edit]

BEGIN
Integer i;
for i := 10 step -1 until 0 do
BEGIN
OutInt(i, 2);
OutImage
END
END

Slate[edit]

10 downTo: 1 do: [| :n | print: n]

Smalltalk[edit]

10 to: 1 by: -1 do:[:aNumber | 
aNumber display.
Character space display.
]

SNOBOL4[edit]

        COUNT = 10
LOOP OUTPUT = COUNT
COUNT = COUNT - 1
GE(COUNT, 0)  :S(LOOP)
END

SNUSP[edit]

++++++++++>++++++++++!/- @!\=@\.@@@-@-----#   atoi
\n counter #\?>.</ \ @@@+@+++++# itoa
loop

Sparkling[edit]

for var i = 10; i >= 0; i-- {
print(i);
}

SSEM[edit]

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 n (stored at address 18) from the illegal instruction c to 32, yielding the actual instruction we use to store n into the array.

10001000000000100000000000000000   0. -17 to c
11001000000001100000000000000000 1. c to 19
11001000000000100000000000000000 2. -19 to c
01001000000000010000000000000000 3. Sub. 18
00010000000001100000000000000000 4. c to 8
01001000000000100000000000000000 5. -18 to c
11001000000001100000000000000000 6. c to 19
11001000000000100000000000000000 7. -19 to c
00000000000000000000000000000000 8. generated at run time
11110000000000010000000000000000 9. Sub. 15
01001000000001100000000000000000 10. c to 18
11110000000000010000000000000000 11. Sub. 15
00000000000000110000000000000000 12. Test
00001000000000000000000000000000 13. 16 to CI
00000000000001110000000000000000 14. Stop
10000000000000000000000000000000 15. 1
11111111111111111111111111111111 16. -1
00000100000001100000000000000000 17. c to 32
01010000000000000000000000000000 18. 10

Swift[edit]

for i in stride(from: 10, through: 0, by: -1) {
println(i)
}

Alternately:

for i in lazy(0...10).reverse() {
println(i)
}

In Swift 1.2 Alternately:

for i in reverse(0 ... 10) {
println(i)
}

Alternately (removed in Swift 3):

for var i = 10; i >= 0; i-- {
println(i)
}

Swift 3:

for i in (0...10).reversed() {
print(i)
}

Tcl[edit]

for {set i 10} {$i >= 0} {incr i -1} {
puts $i
}
# puts "We have liftoff!"

TI-83 BASIC[edit]

 
:For(I,10,0,-1
:Disp I
:End
 

TI-89 BASIC[edit]

Local i
For i, 10, 0, –1
Disp i
EndFor

Trith[edit]

10 inc iota reverse [print] each
10 [dup print dec] [dup 0 >=] while drop

TUSCRIPT[edit]

 
$$ MODE TUSCRIPT
LOOP n=10,0,-1
PRINT n
ENDLOOP
 

UnixPipes[edit]

Works with: OpenBSD version 4.9
yes '' | cat -n | head -n 11 | while read n; do
expr $n - 1
done | tail -r

This pipe uses several nonstandard commands: cat -n and tail -r might not work with some systems. If there is no tail -r, try tac.

UNIX Shell[edit]

Works with: Bourne Shell
i=10
while test $i -ge 0; do
echo $i
i=`expr $i - 1`
done

Works with: bash
for(( Z=10; Z>=0; Z-- )); do
echo $Z
done

Works with: Bourne Shell
Library: jot
for i in `jot - 10 0 -1`; do
echo $i
done
Works with: Bourne Shell
for i in `seq 10 -1 0`; do
echo $i
done
 
# or better yet
seq 10 -1 0
 

Ursa[edit]

decl int i
for (set i 10) (> i -1) (dec i)
out i endl console
end for

V[edit]

10 
[0 >]
[dup puts pred]
while

Vedit macro language[edit]

for (#1 = 10; #1 >= 0; #1--) {
Num_Type(#1)
}

Visual Basic .NET[edit]

For i = 10 To 0 Step -1
Console.WriteLine(i)
Next

Wart[edit]

for i 10 (i >= 0) --i
prn i

XPL0[edit]

include c:\cxpl\codes;          \intrinsic 'code' declarations
int I;
for I:= 10 downto 0 do
[IntOut(0, I); CrLf(0)]

zkl[edit]

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)

ZX Spectrum Basic[edit]

10 FOR l = 10 TO 0 STEP -1
20 PRINT l
30 NEXT l