Kotlin Continue
Chapter:
Kotlin
Last Updated:
02-03-2018 01:11:06 UTC
Program:
/* ............... START ............... */
fun main(args: Array<String>) {
for (i in 1..5) {
println("$i printed.")
if (i > 3 && i < 5) {
continue
}
println("$i Exit from continue .")
}
}
/* ............... END ............... */
Output
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 .
Notes:
-
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.
Tags
Kotlin Continue , Kotlin, Continue Example