R Tutorial – We shall learn R loop statements (repeat, while, for) provided by R programming language to incorporate controlled repetition of executing a block of statements in R code.
R Loop Statements
Repeating execution of a block of statements in a controlled way is an important aspect in any functional programming language. It helps to keep the code concise and clean.
R programming language provides three looping statements. They are :
- R repeat loop – A block of statements are repeated forever. A breaking condition has to be provided inside the repeat block to come out of the loop.
- R while loop – A block of statements are executed repeatedly in a loop till the condition provided to while statement returns TRUE.
- R for loop – A block of statements are executed for each of the items in the list provided to the for loop.
R language also provides a provision to break a loop abruptly.
- R break statement – You may provide an additional condition inside any of the R loops mentioned above. When the condition is satisfied, providing a break statement in conditional code breaks the immediate loop.
In this R tutorial, we have learnt about R loop statements – repeat loop, while loop and for loop. Also we learnt about break statement to break any of the loops abruptly.