Skip to content
Prev 132847 / 398502 Next

Conditionally incrementing a loop counter: Take 2

Mike Jones wrote:
Hi Mike,
Is this what you want?

i<-1
while(i < 11) {
  if(runif(1) < 0.5) i<-i+1
  print(i)
}

This increments if the condition is met, doesn't if it is not met.

Jim