loading...

re: Imaginary Language Features VIEW POST

FULL DISCUSSION
 

I find myself every now and then missing the loop-and-a-half construct where you need to do some preparation before testing the loop condition and this preparation needs to be repeated on every iteration. The syntax could be something like this:

do {
  // Stuff
} while (condition) {
  // More stuff
}

which already resembles the two existing loop syntaxes, while and do-while. So this would execute Stuff always first, and while the condition is true, it would execute More stuff, Stuff, and then test the condition again.

The way to accomplish this now is with an infinite while loop with a conditional break in the middle. I find this somewhat inelegant, and also harder to see that there is a condition that causes the loop to terminate.

 

Can you give an example of when this would be useful?

Code of Conduct Report abuse