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

R Next Statement

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"
r_loops.htm
Advertisements