How to Write a repeat-Loop in R Programming (Example Code)
In this article, I’ll show how to write and run a repeat-loop in the R programming language.
Example: Running repeat-Loop in R Programming Language
my_data <- 1 # Specify example data object |
my_data <- 1 # Specify example data object
repeat{ # Entering repeat-loop my_data <- c(my_data, # Creating some output my_data[length(my_data)] + 1) if(length(my_data) >= 8) { # Check whether repeat-loop should continue break # End of repeat-loop } } |
repeat{ # Entering repeat-loop my_data <- c(my_data, # Creating some output my_data[length(my_data)] + 1) if(length(my_data) >= 8) { # Check whether repeat-loop should continue break # End of repeat-loop } }
my_data # Returning output # [1] 1 2 3 4 5 6 7 8 |
my_data # Returning output # [1] 1 2 3 4 5 6 7 8