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

bookcontinue Statement in Kotlin

Scorri per mostrare il 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

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?

Seleziona la risposta corretta

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 3. Capitolo 3

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Sezione 3. Capitolo 3
some-alt