-- | A while loop, run the second argument while the first argument is true.
--   The action is run in a 'scope'. See also 'loop'.
--
-- @
-- x <- 'mutable_' x
-- 'while' (x '%<' 10) $ do
--    x '@=' x '+' 1
-- @
while :: Exp Bool -> Action () -> Action ()
while test act = do
    start <- newLabel
    label start
    iff_ test (scope act >> goto start)

-- | A loop with a @break@ command. Run the action repeatedly until the breaking action
--   is called. The action is run in a 'scope'. See also 'while'.
--
-- @
-- x <- 'mutable_' x
-- 'loop' $ \\break -> do
--     'iff_' (x '%>=' 10) break
--     x '@=' x '+' 1
-- @
while :: Exp Bool -> Action () -> Action ()
while test act = do
    start <- newLabel
    label start
    iff_ test (scope act >> goto start)

-- | A loop with a @break@ command. Run the action repeatedly until the breaking action
--   is called. The action is run in a 'scope'. See also 'while'.
--
-- @
-- x <- 'mutable_' x
-- 'loop' $ \\break -> do
--     'iff_' (x '%>=' 10) break
--     x '@=' x '+' 1
-- @
while test act = do
    start <- newLabel
    label start
    iff_ test (scope act >> goto start)

-- | A loop with a @break@ command. Run the action repeatedly until the breaking action
--   is called. The action is run in a 'scope'. See also 'while'.
--
-- @
-- x <- 'mutable_' x
-- 'loop' $ \\break -> do
--     'iff_' (x '%>=' 10) break
--     x '@=' x '+' 1
-- @