Loop Control Statements
Loop control statements change execution from its normal sequence. Following are the loop control statements provided by R Language:
- Break Statement: The break keyword is a jump statement that is used to terminate the loop at a particular iteration.
- Next Statement: The next statement is used to skip the current iteration in the loop and move to the next iteration without exiting from the loop itself.
R
# R program for break statement no <- 15:20 for (val in no) { if (val == 17) { break } print ( paste ( "Values are: " , val)) } print ( "------------------------------------" ) # R Next Statement Example for (val in no) { if (val == 17) { next } print ( paste ( "Values are: " , val)) } |
Output:
[1] "Values are: 15" [1] "Values are: 16" [1] "------------------------------------" [1] "Values are: 15" [1] "Values are: 16" [1] "Values are: 18" [1] "Values are: 19" [1] "Values are: 20"
Note: For more information, refer Break and Next statements in R
Learn R Programming
R is a Programming Language that is mostly used for machine learning, data analysis, and statistical computing. It is an interpreted language and is platform independent that means it can be used on platforms like Windows, Linux, and macOS.
In this R Language tutorial, we will Learn R Programming Language from scratch to advance and this tutorial is suitable for both beginners and experienced developers).