0 votes
1 view
in R Programming by (7.3k points)

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 (25.4k points)

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...