I am working in R and I am trying to change the limit of a for loop within the loop itself, but I cannot succeed.
Here's my toy peace of code:
setwd(".")
options(stringsAsFactors = FALSE)
cat("\014")
set.seed(11)
execution_limit <- 10
for(exe_i in 1:execution_limit)
{
cat("(exe_i = ", exe_i," / ", execution_limit, ")\n", sep="")
Sys.sleep(0.1)
if(exe_i == 7) {
execution_limit <- 15
}
}
Printed output:
(exe_i = 1 / 10)
(exe_i = 2 / 10)
(exe_i = 3 / 10)
(exe_i = 4 / 10)
(exe_i = 5 / 10)
(exe_i = 6 / 10)
(exe_i = 7 / 10)
(exe_i = 8 / 15)
(exe_i = 9 / 15)
(exe_i = 10 / 15)
The loop stops after 10 iterations, but I would like to go on until the 15th iteration. How can I do that?
Thanks