Logo

Programming-Idioms

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

Idiom #256 Count backwards

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

import Control.Monad (forM_)
forM_ (reverse [0..5]) print

This must be used in an IO context.
foldl  (\res x-> x:res) [] [0..5]

This creates a reversed list (and prints it if you're in REPL)
for A in reverse 0 .. 5 loop
   Put_Line (A'Image);
end loop;

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