In this tutorial you will learn about the R next Statement and its application with practical example.
R next Statement
In R, the next statement gives you way to skip over the current iteration of any loop and continues with the next iteration. When a next statement is encountered in the loop, the rest of statements in the loop body for current iteration and returns the program execution to the very first statement in the loop body. It does not terminates the loop rather continues with the next iteration.
Syntax:-
1 2 3 |
if (condition) { next } |
Example:-
1 2 3 4 5 6 7 8 9 10 11 |
print("W3Adda - R Next Statement") count <- 0 while (count <= 10) { count = count + 1 if (count == 5) { print("5 is skipped") next } print("Inside loop") } print("Out of while loop") |
When we run the above swift program, we will see following output –
Output:-
As you can see when ctr == 5, next statement is executed which causes the current iteration to end and the control moves on to the next iteration.