Logo

Programming-Idioms

History of Idiom 78 > diff from v41 to v42

Edit summary for version 42 by :
Restored version 40

Version 41

2016-02-18, 16:58:01

Version 42

2016-02-18, 18:48:15

Idiom #78 "do while" loop

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

Idiom #78 "do while" loop

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

Code
for{
   someThing()
   …
   someOtherThing()
   if !c {
     break
   }
}
Code
for{
   someThing()
   …
   someOtherThing()
   if !c {
     break
   }
}
Comments bubble
Go has no do while loop, use the for loop, instead.
Comments bubble
Go has no do while loop, use the for loop, instead.
Doc URL
https://golang.org/ref/spec#For_statements
Doc URL
https://golang.org/ref/spec#For_statements
Demo URL
http://play.golang.org/p/aNVIjY8oVK
Demo URL
http://play.golang.org/p/aNVIjY8oVK
Code
do {
  someThing();
  someOtherThing();
} while(c);
Code
do {
  someThing();
  someOtherThing();
} while(c);
Comments bubble
The block code is not repeated in the source.
Comments bubble
The block code is not repeated in the source.