Saturday, 18 July 2015

R: next statement

“next” is used to skip iteration of the loop. It is just like continue statement in Java.


NextEx.R
for(i in 1:10){
 if(i%%2 == 0)
  next
 print(i)
}


Above program prints all odd numbers up to 10.

$ Rscript NextEx.R 
[1] 1
[1] 3
[1] 5
[1] 7
[1] 9

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment