R Break Statement
In the R language, the break statement is used to break the execution and for an immediate exit from the loop. In nested loops, break exits from the innermost loop only and control transfer to the outer loop.
It is useful to manage and control the program execution flow. We can use it to various loops like: for, repeat, etc.
There are basically two usages of break statement which are as follows:
- When the break statement is inside the loop, the loop terminates immediately and program control resumes on the next statement after the loop.
- It is also used to terminate a case in the switch statement.
Note: We can also use break statement inside the
else branch of
There is the following syntax for creating a break statement in R
Example 1: Break in repeat loop
Example 3: Break in while loop
Example 4: Break in for loop