Logo

Programming-Idioms

  • Go
  • Python
  • Pascal

Idiom #78 "do while" loop

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

repeat
  Something;
  SomethingElse;
until not c;

This is the correct implementation, it repeats the block until condition c is not true
repeat
  Something;
  SomethingElse;
until
  c;
for done := false; !done; {
	someThing()
	someOtherThing()
	done = !c()
}

Explicit loop variable done shows the intent.
for{
   someThing()
   someOtherThing()
   if !c {
     break
   }
}

Go has no do while loop, use the for loop, instead.
x = True
while x:
    x = c

Python does not have a `do-while` loop syntax.
while True:
    do_something()
    if not c:
        break
loop
   stuff();
   if not c then
      exit;
   end if;
end loop;

New implementation...
< >
deleplace