Logo

Programming-Idioms

  • Dart
  • Go

Idiom #78 "do while" loop

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

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.
do {
  someThing();
  someOtherThing();
} while(c);
loop
   stuff();
   if not c then
      exit;
   end if;
end loop;

New implementation...
< >
deleplace