continue Statement in Kotlin
Swipe to show menu
The continue statement is a powerful tool in Kotlin loops. When you use continue inside a loop, it immediately ends the current iteration and jumps to the next one. This means that any code after the continue statement within the loop block is skipped for that iteration. You often use continue when you want to ignore certain cases or values while looping, but still continue processing the rest.
Main.kt
In the example above, the loop goes through numbers from 1 to 10. When the current number i is even (i % 2 == 0), the continue statement is executed. This skips the rest of the code in the loop for that iteration, so println(i) is not called for even numbers. As a result, only odd numbers are printed. Using continue in this way changes the normal flow of the loop by allowing you to skip processing for certain values without stopping the loop entirely.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat