Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer continue Statement in Kotlin | Advanced Loop Techniques
Kotlin Loops

bookcontinue Statement in Kotlin

Veeg om het menu te tonen

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

Main.kt

copy

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.

question mark

What happens when the continue statement is executed in a loop?

Selecteer het correcte antwoord

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 3

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Sectie 3. Hoofdstuk 3
some-alt