Tim Tim - 3 months ago 22
R Question

do-while loop in R

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

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.