Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #256 Count backwards

Print the numbers 5, 4, ..., 0 (included), one line per number.

for A in reverse 0 .. 5 loop
   Put_Line (A'Image);
end loop;
for (int i = 5; i >= 0; i--) {
	printf("%d\n", i);
}
(doseq [n (range 5 0 -1)]
  (println n))
for (int i = 5; i >= 0; --i) {
	std::cout << i;
}
using System;
for (int i = 5; i >= 0; i--)
{
    Console.WriteLine(i);
}
for (int i = 5; i >= 0; i--) {
  print(i);
}
do i=5,0,-1
  print *,i
end do
import "fmt"
for i := 5; i >= 0; i-- {
	fmt.Println(i)
}
foldl  (\res x-> x:res) [] [0..5]
import Control.Monad (forM_)
forM_ (reverse [0..5]) print
for (let i = 5; i >= 0; i--) {
  console.log(i)
}
import static java.lang.System.out;
for (int i = 5; i != -1; out.println(i--));
import static java.lang.System.out;
import static java.util.stream.IntStream.iterate;
iterate(5, i -> i - 1)
    .limit(6)
    .forEach(out::println);
for(int i=5 ; i>=0 ; i--) {
    System.out.println(i);
}
(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 }
(0..=5).rev().for_each(|i| println!("{}", i));
for i in (0..=5).rev() {
    println!("{}", i);
}
(let loop ([x 5])
  (when (>= x 0)
    (display x)
    (newline)
    (loop (sub1 x))))
5 to: 0 by: -1 do: [:i | Transcript showln: i asString].
Imports System
For i = 5 To 0 Step -1
    Console.WriteLine(i)
Next

New implementation...
< >
programming-idioms.org