As like every programming language in Kotlin continue expression skips the current iteration of the enclosing loop, and the control of the program jumps to the end of the loop body.
In the above program program if the value of i is greater than three and less than five continue expression is called and control returns back to loop body.
Continue statment is used to stop the execution of the body and control goes back to the next iteration.
Kotlin Code:
1 2 3 4 5 6 7 8 9 10 11 12 | fun main(args: Array<String>) { for (i in 1..5) { println("$i printed.") if (i > 3 && i < 5) { continue } println("$i Exit from continue .") } } |
Output:
1 2 3 4 5 6 7 8 9 10 11 | 1 printed. 1 Exit from continue . 2 printed. 2 Exit from continue . 3 printed. 3 Exit from continue . 4 printed. 5 printed. 5 Exit from continue . |