You can change the loop index in a for loop, but this will not affect the execution of the loop; see "Details" ?"for" :
The 'seq' in a 'for' loop is evaluated at the start of the loop; changing it subsequently does not affect the loop. If 'seq' has length zero the body of the loop is skipped. Otherwise the variable 'var' is assigned in turn the value of each element of 'seq'. You can assign to 'var' within the body of the loop, but this will not affect the next iteration. When the loop terminates, 'var' remains as a variable containing its latest value.
Use a while loop and index it manually:
i <- 1 while(i < 100) { # do stuff if(condition) { i <- i+3 } else { i <- i+1 } }
Joshua ulrich
source share