View Problem

Perform an action multiple times based on a boolean condition, checked before the first action (WHILE .. DO)

Starting with a variable x=1, Print the sequence "1,2,4,8,16,32,64,128," by doubling x and checking that x is less than 150.
DiskEdit
python
x = 1
while x < 150:
print '%s, ' % x,
x *= 2
DiskEdit
clojure
(take-while #(< % 150) (iterate #(* 2 %) 1))
ExpandDiskEdit
fsharp
let mutable x = 1
while x < 150 do printf "%d, " x ; (x <- x * 2) done
DiskEdit
fsharp
// The problem is clearly geared towards imperative languages ;-)
// No need to mutate any variable, here's how to do it loop-free functional:
let rec powers2 i = seq { if i < 150 then yield i; yield! powers2 (i*2) }
powers2 1 |> Seq.iter (fun i -> printf "%i, " i)
ExpandDiskEdit
fantom
x := 1
while (x < 150) {
Env.cur.out.print("$x,")
x *= 2
}
echo
ExpandDiskEdit
java
int x = 1;
while (x < 150) {
System.out.println(x+",");
x*=2;
}
ExpandDiskEdit
cpp C++/CLI .NET 2.0
int x = 1;

while (x < 150) { x *= 2; Console::Write("{0},", x); }
Console::WriteLine();
ExpandDiskEdit
cpp
for (int x = 1; x < 150; x *= 2) { std::cout << x << ","; }
std::cout << std::endl;
DiskEdit
haskell
main :: IO ()
main = loop 1
where
loop x | x < 150 = do
putStr (show x ++ ",")
loop (x * 2)
loop _ = return ()
DiskEdit
haskell
main = mapM_ print $ takeWhile (<150) $ iterate (* 2) 1

Submit a new solution for python, clojure, fsharp, fantom ...
There are 10 other solutions in additional languages (csharp, erlang, groovy, ocaml ...)