Next R - r - learn r - r programming
- A next statement is useful when we want to skip the current iteration of a loop without terminating it.
- On come across next, the R parser skips additional evaluation and starts next iteration of the loop.
- Here we create a vector v, which has consecutive numbers from 5 to 10 (5:10).
- The for loop condition we used val value, it takes on the value of corresponding element of v.
- If the value is equal to 7, the current evaluation stops which means value is not printed, but the loop continues with the next iteration. Here we use the next statement inside a condition to check if the value is equal to 7.
- print() is used to print the value, that value stored in val variable.
- Here in this output we display the 5 6 8 9 10 values which specifies to, if the value is equal to 7, the current evaluation stops (7 value is not printed), but loop continues with the next iteration 8 9 10 display on the output.