
- R - Home
- R - Overview
- R - Environment Setup
- R - Basic Syntax
- R - Data Types
- R - Variables
- R - Operators
- R - Decision Making
- R - Loops
- R - Functions
- R - Strings
- R - Vectors
- R - Lists
- R - Matrices
- R - Arrays
- R - Factors
- R - Data Frames
- R - Packages
- R - Data Reshaping
- R - CSV Files
- R - Excel Files
- R - Binary Files
- R - XML Files
- R - JSON Files
- R - Web Data
- R - Database
- R Charts & Graphs
- R - Pie Charts
- R - Bar Charts
- R - Boxplots
- R - Histograms
- R - Line Graphs
- R - Scatterplots
- R Statistics Examples
- R - Mean, Median & Mode
- R - Linear Regression
- R - Multiple Regression
- R - Logistic Regression
- R - Normal Distribution
- R - Binomial Distribution
- R - Poisson Regression
- R - Analysis of Covariance
- R - Time Series Analysis
- R - Nonlinear Least Square
- R - Decision Tree
- R - Random Forest
- R - Survival Analysis
- R - Chi Square Tests
- R Useful Resources
- R - Interview Questions
- R - Quick Guide
- R - Cheatsheet
- R - Useful Resources
- R - Discussion
R - next statement
The next statement in R programming language is useful when we want to skip the current iteration of a loop without terminating it. On encountering next, the R parser skips further evaluation and starts next iteration of the loop.
Syntax
The basic syntax for creating a next statement in R is −
next
Flow Diagram

Example
v <- LETTERS[1:6] for ( i in v) { if (i == "D") { next } print(i) }
When the above code is compiled and executed, it produces the following result −
[1] "A" [1] "B" [1] "C" [1] "E" [1] "F"
Example - Using next statement in while loop
x <- 10 while(x < 20) { x <- x + 1 if(x == 15){ next } cat("value of x : " , x ,"\n") }
When the above code is compiled and executed, it produces the following result −
value of x : 11 value of x : 12 value of x : 13 value of x : 14 value of x : 16 value of x : 17 value of x : 18 value of x : 19 value of x : 20
Example - Using next statement in for loop
v <- LETTERS[1:10] for ( i in v) { if(i == "C"){ next } print(i) }
When the above code is compiled and executed, it produces the following result −
[1] "A" [1] "B" [1] "D" [1] "E" [1] "F" [1] "G" [1] "H" [1] "I" [1] "J"
r_loops.htm
Advertisements