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 specify 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 :
repeat {
statement
if(condition) {
break
}
}
Example :
>x <- 1
>repeat
{
print(x)
x = x+1
if (x == 6)
{
break
}
}
Output :
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
Thanks, TAMATAM
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 specify 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 :
repeat {
statement
if(condition) {
break
}
}
Example :
>x <- 1
>repeat
{
print(x)
x = x+1
if (x == 6)
{
break
}
}
Output :
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
Thanks, TAMATAM
No comments:
Post a Comment
Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.