R repeat Loop

In this tutorial you will learn about the R repeat Loop and its application with practical example.

R repeat Loop

The repeat loop executes a block of code repeatedly, until it meets an explicit condition to break and exit the loop. Repeat loop construct don’t have any conditional check over iterations, thus it is mandatory to define an explicit condition with a break statement inside loop body, which allows program to exit the loop. Otherwise, it will result into an infinite loop.

Syntax:-

Example:-

Here, we have defined ctr variable and initialized it with 1. Next, we have a repeat loop and inside the loop body we have a print statement that prints “Hello, World!” string after this we are incrementing ctr value by 1, then we have an if condition which break the loop if ctr > 5.

When we run the above R script, we see the following output –

Output:-

Recommended:-  R Scope
In this tutorial we have learn about the R repeat Loop and its application with practical example. I hope you will like this tutorial.