Logo

Programming-Idioms

  • Dart
  • Rust

Idiom #78 "do while" loop

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

while {
   doStuff();
   c
} { /* EMPTY */ }

Use compound expression for the while loop condition.
loop {
    doStuff();
    if !c { break; }
}

Rust has no do-while loop with syntax sugar. Use loop and break.
do {
  someThing();
  someOtherThing();
} while(c);
loop
   stuff();
   if not c then
      exit;
   end if;
end loop;

New implementation...
< >
deleplace