R next statement

A next statement is useful when we want to skip the current iteration of a loop without terminating it. next statement is opposite to break statement. If condition met, break will terminates from loops.

Syntax:

next

Next in for loop

x<-1:10 # Define variable x

for (i in x) { if(i==5) { next } print(i) }

Output: Output is missing 5

[1] 1
[1] 2
[1] 3
[1] 4
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10

techs<-c("R","Python","SAS","MySQL")

for (i in techs) { if(i==’SAS’) { next } print(i) }

Ouput:

[1] “R”
[1] “Python”
[1] “MySQL”

Powered by WordPress