Programming-Idioms

History of Idiom 78 > diff from v11 to v12

Edit summary for version 12 :

Version 11

2015-09-05, 13:09:28

Version 12

2015-09-05, 13:10:25

Idiom #78 "do while" loop

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

Idiom #78 "do while" loop

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

Code
dowhile :: (a -> Bool) -> IO a -> IO a
dowhile c b = do a <- b
  if (c a) then dowhile c b else return a

dowhile (/="END") getLine
Code
dowhile :: (a -> Bool) -> IO a -> IO ()
dowhile c b = do a <- b
  if (c a) then dowhile c b
            else return ()

dowhile (/="END") getLine