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).

Similar Reads

Why Learn R Programming Language?

R programming is used as a leading tool for machine learning, statistics, and data analysis. R is an open-source language that means it is free of cost and anyone from any organization can install it without purchasing a license. It is available across widely used platforms like windows, Linux, and macOS. R programming language is not only a statistic package but also allows us to integrate with other languages (C, C++). Thus, you can easily interact with many data sources and statistical packages. Its user base is growing day by day and has vast community support. R Programming Language is currently one of the most requested programming languages in the Data Science job market that makes it the hottest trend nowadays....

Key Features and Applications

Some key features of R that make the R one of the most demanding job in data science market are:...

Download and Installation

There are many IDE’s available for using R in this article we will dealing with the installation of RStudio in R....

Hello World in R

R Program can be run in several ways. You can choose any of the following options to continue with this tutorial....

Fundamentals of R

...

Data Types

Variables:...

Basics of Input/Output

...

Decision Making

...

Control Flow

...

Loop Control Statements

...

Functions

...

Data Structures

...

Error Handling

Each variable in R has an associated data type. Each data type requires different amounts of memory and has some specific operations which can be performed over it. R supports 5 type of data types. These are –...

Charts and Graphs

...

Statistics

Taking Input from the User:...

Contact Us