R Repeat Loop

R Repeat Loop does the execution of a set of statements in a loop until a break condition is met. In this R Tutorial, we shall learn Repeat Loop syntax and execution flow with Example R Scripts.

Syntax of R Repeat Loop

repeat {
    if(stop_condition) {

Execution Flow

Following picture depicts the flow of execution in and around the repeat loop statement.

R Repeat Loop

Breaking Condition

Breaking is done using an R if statement.

It is optional. But if you do not place a breaking condition in the repeat loop statement, the statements in the repeat block will get executed for ever in an infinite loop.

Breaking Condition should return a boolean value, either TRUE or FALSE.

The placement of breaking condition is up to the developer. You may keep it before the “block of statements” block or after it.

Example for R Repeat Loop

Conclusion :

In this R Tutorial, we have learnt Repeat Loop, its Syntax and Execution Flow with Example R Scripts.