The next statement is used to skip any remaining statements in the loop and continue executing. In simple words, a next statement is a statement which skips the current iteration of a loop without terminating it. When the next statement is encountered, the R parser skips further evaluation and starts the next iteration of the loop.
This statement is mostly used with for loop and while loop.
Note: In else branch of the if-else statement, the next statement can also be used.
Syntax
There is the following syntax for creating the next statement in R
Flowchart
Example 1: next in repeat loop
Output:
Example 2: next in while loop
Output:
Example 3: next in for loop
Output:
Example 4
Output:
Example 5
Output:
No comments:
Post a Comment