Javatpoint Logo
Javatpoint Logo

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:

  1. When the break statement is inside the loop, the loop terminates immediately and program control resumes on the next statement after the loop.
  2. It is also used to terminate a case in the switch statement.

Note: We can also use break statement inside the else branch of if...else statement.

Syntax

There is the following syntax for creating a break statement in R

Flowchart

R Break statement

Example 1: Break in repeat loop

Output:

R Break statement

Example 2

Output:

R Break statement

Example 3: Break in while loop

Output:

R Break statement

Example 4: Break in for loop

Output:

R Break statement

Example 5

Output:

R Break statement
Next TopicR For Loop





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA