Loop concepts - the repeat loop

The repeat loop is used to iterate a certain calculation over a vector or dataframe. There is no provision to check the condition to exit the loop; generally a break statement is used to exit the loop. If you fail to provide any break condition within the repeat loop, you will end up running the repeat loop infinitely. Let's look at the code showing how to write a repeat loop. The break condition used in the following code is if x > 2.6:

x <- 100
repeat {
  print(x)
  x = sqrt(x)+10
  if (x > 2.6){
    break
  }
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.189.220