...

/

repeat Loops

repeat Loops

We will be learning all about the repeat statement in this lesson.

Syntax of a repeat loop

The syntax for repeat loop in R language:

repeat 
{
  statement
}

In the statement block, we must use the break statement to exit the loop.

The repeat loop runs as long as it is not broken explicitly.

Press + to interact
R
myNumber <- 1
repeat
{
print(myNumber)
myNumber = myNumber + 1
if(myNumber > 10)
break
}

Here, the break statement is executed when the conditional ...