Repeat Loop in R Programming:

A repeat loop is used to iterate over a block of code multiple number of times.

There is no condition check in repeat loop to exit the loop.

We must ourselves put a condition explicitly inside the body of the loop and use the break statement to exit the loop. Failing to do so will result into an infinite loop.

Syntax of repeat loop

repeat {
statements
Break 
}

Here Break statement is used explicitly to exit the loop

Let’s Work one one example to understand:

Here in this example : we are using repeat Loop inside the repeat loop we are printing the x variable Value and Incrementing the x , if explicit break is not used , this repeat loop prints infinite times, so Break should be used in the repeat Loop.