Logo

Programming-Idioms

  • Python
  • Java

Idiom #256 Count backwards

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

import static java.lang.System.out;
import static java.util.stream.IntStream.iterate;
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
import static java.lang.System.out;
for (int i = 5; i != -1; out.println(i--));
print(*reversed(range(6)), sep='\n')
for i in range(5, -1, -1):
    print(i)
for A in reverse 0 .. 5 loop
   Put_Line (A'Image);
end loop;

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