View Problem

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

Simulate rolling a die until you get a six. Produce random numbers, printing them until a six is rolled. An example output might be "4,2,1,2,6"
DiskEdit
python
import random, itertools

def dice():
while True:
yield random.randint(1,6)

print ", ".join(str(d) for d in itertools.takewhile(lambda x: x < 6, dice()))
ExpandDiskEdit
erlang
Pred = fun (DiceRoll) -> DiceRoll =/= 6 end,
Action = fun (DiceRoll) -> io:format("~B,", [DiceRoll]), dice_roll() end,

do_while(Pred, Action, dice_roll()).
DiskEdit
erlang
-module(dice).
-export([start/0]).

start() ->
roll(dice_roll()).

roll(6) ->
io:format("6~n", []);
roll(N) ->
io:format("~B,", [N]),
roll(dice_roll()).

dice_roll() -> random:uniform(6).
DiskEdit
clojure
(loop [r (rand-int 6)]
(if (= r 5)
nil
(do
(println r)
(recur (rand-int 6)))))
ExpandDiskEdit
cpp C++/CLI .NET 2.0
Random^ rnd = gcnew Random;

int dice = rnd->Next(1, 7); Console::Write("{0}", dice);
do { Console::Write(",{0}", (dice = rnd->Next(1, 7))); } while (dice != 6);
Console::WriteLine();

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