Logo

Programming-Idioms

  • PHP
  • Haskell
  • Clojure
  • Js

Idiom #78 "do while" loop

Execute a block once, then execute it again as long as boolean condition c is true.

do {
   something();
} while (c);
do {
    echo '.';
} while ($c);
doowhile c b = do a <- b; if c a
                          then doowhile c b
                          else return a

doowhile (=="") getLine
gg
(loop []
  (do something)
  (when c
    (recur)))

The first argument to loop can be used to define variables which are scoped to the loop. Values passed to recur are used for the next iteration.
loop
   stuff();
   if not c then
      exit;
   end if;
end loop;

New implementation...
< >
deleplace