Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
- Ada
- C
- Clojure
- C++
- C#
- Dart
- Fortran
- Go
- Haskell
- Haskell
- JS
- Java
- Java
- Java
- Lisp
- Lua
- PHP
- Pascal
- Perl
- Python
- Python
- Ruby
- Rust
- Rust
- Scheme
- Smalltalk
- VB
for A in reverse 0 .. 5 loop
Put_Line (A'Image);
end loop;
for (int i = 5; i >= 0; i--) {
printf("%d\n", i);
}
for (int i = 5; i >= 0; --i) {
std::cout << i;
}
for (int i = 5; i >= 0; i--) {
print(i);
}
do i=5,0,-1
print *,i
end do
foldl (\res x-> x:res) [] [0..5]
This creates a reversed list (and prints it if you're in REPL)
for (let i = 5; i >= 0; i--) {
console.log(i)
}
iterate(5, x -> x - 1)
.limit(6)
.forEach(out::println);
for(int i=5 ; i>=0 ; i--) {
System.out.println(i);
}
Note that the int type is signed
(dotimes (i 6) (print (- 5 i)))
for i=5, 0, -1 do
print(i)
end
$values = range(0, 5);
$valuesReversed = array_reverse($values);
foreach($valuesReversed as $value)
{
printf("%s\n", $value);
}
for i := 5 downto 0 do writeln(i);
print "$_\n" for reverse (0..5);
for i in range(5, -1, -1):
print(i)
print(*reversed(range(6)), sep='\n')
5.downto(0){|n| puts n }
(let loop ([x 5])
(when (>= x 0)
(display x)
(newline)
(loop (sub1 x))))
Named let is a common way of iterating in Scheme. The "loop" label could have been "cat," for instance.
5 to: 0 by: -1 do: [:i | Transcript showln: i asString].