Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (7.3k points)
edited by

Suppose you have a for loop like so

for(n in 1:5) {

  #if(n=3) # skip 3rd iteration and go to next iteration

  cat(n)

}

How would one skip to the next iteration if a certain condition is met?

1 Answer

0 votes
by
edited by

R has the next statement that is used to skip the current iteration of the loop without terminating the loop.

For example:

for(n in 1:5) {

  if(n==3) 

    next    #skip 3rd iteration and go to next iteration

  cat(n)

}

Output:

1245

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...