Task

Start an integer value at   1024.

Loop while it is greater than zero.

Print the value (with a newline) and divide it by two each time through the loop.



Related tasks

   Loop over multiple arrays simultaneously
   Loops/Break
   Loops/Continue
   Loops/Do-while
   Loops/Downward for
   Loops/For
   Loops/For with a specified step
   Loops/Foreachbas
   Loops/Increment loop index within loop body
   Loops/Infinite
   Loops/N plus one half
   Loops/Nested
   Loops/While
   Loops/with multiple ranges
   Loops/Wrong ranges


#include "share/atspre_staload.hats"
 
fn
loop_while () : void =
  let
    fun
    loop {n : int | 0 <= n} .<n>.
         (n : uint n) : void =
      if n <> 0U then
        begin
          println! (n);
          loop (n / 2U)
        end
  in
    loop 1024U
  end
 
implement
main0 () =
  loop_while ()