Kotlin continue

In this tutorial you will learn about the Kotlin continue and its application with practical example.

Kotlin continue statement

The continue statement gives you way to skip over the current iteration of any loop. When a continue statement is encountered in the loop, the kotlin interpreter ignores 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:-

Example:-

Output:-

As you can see when ctr == 5, continue statement is executed which causes the current iteration to end and the control moves on to the next iteration.

Kotlin Labeled continue

The standard unlabeled continue statement is used to skip the current iteration of nearest enclosing loop. In Kotlin, there is another form of continue (labeled continue ) statement is used to skip iteration of specified loop (can be outer loop). In Kotlin, Label is an identifier which is followed by @ sign, for example [email protected], [email protected]

Recommended:-  Kotlin Type Conversion

Example:-

Output:-

Here, when i == 2 expression is evaluated to true, [email protected] is executed which skips the current iteration of the enclosed loop and return control to the loop marked with label [email protected].

In this tutorial we have learn about the Kotlin continue and its application with practical example. I hope you will like this tutorial.