do-while loop in R

Tim picture Tim · Dec 5, 2010 · Viewed 151.6k times · Source

I was wondering about how to write do-while-style loop?

I found this post:

you can use repeat{} and check conditions whereever using if() and exit the loop with the "break" control word.

I am not sure what it exactly means. Can someone please elaborate if you understand it and/or if you have a different solution?

Answer

A Salcedo picture A Salcedo · Dec 5, 2010

Pretty self explanatory.

repeat{
  statements...
  if(condition){
    break
  }
}

Or something like that I would think. To get the effect of the do while loop, simply check for your condition at the end of the group of statements.