Kotlin unlabelled continue
Last Updated :
10 May, 2025
In this article, we will learn how to use continue in Kotlin. While working with loops in programming, sometimes, it is desirable to skip the current iteration of the loop. In that case, we can use the continue statement in the program. continue is used to repeat the loop for a specific condition. It skips the following statements and continues with the next iteration of the loop.
There are two types of continue in Kotlin.
We are going to learn how to use unlabelled continue in while, do-while, and for loops.
Use of unlabelled continue in a while loop
In Kotlin, unlabelled continue is used to skip the current iteration of the nearest enclosing while loop. If the condition for continue is true, then it skips the following instructions of continue and reaches to the starting of while loop. Again, it will check for the condition and loop will be in repetition mode until it becomes false.
Syntax of unlabelled continue in a while loop
while(condition) {
//code
if(condition for continue) {
continue
}
//code
}
Flowchart

Kotlin program to use the continue in a while loop
Kotlin
fun main(args: Array<String>) {
var num = 0
while (num <= 12) {
if (num % 3 == 0) {
num++
continue
}
println(num)
num++
}
}
Output:
1
2
4
5
7
8
10
11
Here, in the above program, we print the numbers and skips all multiples of 3. The expression (num % 3 == 0) is used to check that number is divisible by 3 or not. If it is multiple of 3 then increment the number without printing it to standard output.
Use of unlabelled continue in a do-while loop
In do-while also we can also use the unlabelled continue to skip the iteration of the nearest closing loop. Here, we need to put the condition for continue in do block. If condition becomes false it will skip the following instruction and transfer control to the while condition.
Syntax of unlabelled continue in a do-while loop
do{
// codes
if(condition for continue) {
continue
}
}
while(condition)
Flowchart

Kotlin program to use continue in a do-while loop
Kotlin
fun main(args: Array<String>) {
var num = 1
do {
if (num <= 5 || num >=15) {
num++
continue
}
println("$num")
num++
} while (num < 20)
}
Output :
6
7
8
9
10
11
12
13
14
In the above program, we have used the condition (num <= 5 || num >=15) to skip the printing of numbers to the standard output which is less than or equal to 5 and greater than or equal to 15. So, it only prints the numbers from 6 to 14.
Use of unlabelled continue in a for loop
In a for loop, we can also use unlabelled continue to skip the current iteration to the closing loop. In the program below, we have taken an array of strings and i the iterator for the traversal of the array planets. The expression ( i < 2 ) skips the iteration of array indices less than two, which means it does not print the strings stored at index 0 and 1.
Syntax for unlabelled continue in a for loop
for(iteration through iterator)
{
//code
if(condition for continue){
continue
}
}
Flowchart

Kotlin program to use continue in a for loop
Kotlin
fun main(args: Array<String>) {
var planets = arrayOf("Earth", "Mars", "Venus", "Jupiter", "Saturn")
for (i in planets.indices) {
if(i < 2){
continue
}
println(planets[i])
}
}
Output:
Venus
Jupiter
Saturn
Similar Reads
Kotlin Tutorial This Kotlin tutorial is designed for beginners as well as professional, which covers basic and advanced concepts of Kotlin programming language. In this Kotlin tutorial, you'll learn various important Kotlin topics, including data types, control flow, functions, object-oriented programming, collecti
4 min read
Kotlin Android Tutorial Kotlin is a cross-platform programming language that may be used as an alternative to Java for Android App Development. Kotlin is an easy language so that you can create powerful applications immediately. Kotlin is much simpler for beginners to try as compared to Java, and this Kotlin Android Tutori
6 min read
Introduction to Activities in Android Activity class is one of the very important parts of the Android Component. Any app, don't matter how small it is (in terms of code and scalability), has at least one Activity class. Unlike most programming languages, in which the main() method is the entry point for that program or application to s
6 min read
Retrofit with Kotlin Coroutine in Android Retrofit is a type-safe http client which is used to retrieve, update and delete the data from web services. Nowadays retrofit library is popular among the developers to use the API key. The Kotlin team defines coroutines as âlightweight threadsâ. They are sort of tasks that the actual threads can e
3 min read
Introduction to Kotlin Kotlin is a statically typed, general-purpose programming language developed by JetBrains, which has built world-class IDEs like IntelliJ IDEA, PhpStorm, Appcode, etc. It was first introduced by JetBrains in 2011 as a new language for the JVM. Kotlin is an object-oriented language, and a better lang
4 min read
Kotlin Data Types The most fundamental data type in Kotlin is the Primitive data type and all others are reference types like array and string. Java needs to use wrappers (java.lang.Integer) for primitive data types to behave like objects but Kotlin already has all data types as objects.There are different data types
3 min read
Kotlin when expression In Kotlin, when replaces the switch operator of other languages like Java. A certain block of code needs to be executed when some condition is fulfilled. The argument of when expression compares with all the branches one by one until some match is found. After the first match is found, it reaches to
6 min read
Kotlin Constructor A constructor is a special member function that is automatically called when an object of a class is created. Its main purpose is to initialize properties or perform setup operations. In Kotlin, constructors are concise, expressive, and provide significant flexibility with features like default para
6 min read
Android RecyclerView in Kotlin In this article, you will know how to implement RecyclerView in Android using Kotlin . Before moving further let us know about RecyclerView. A RecyclerView is an advanced version of ListView with improved performance. When you have a long list of items to show you can use RecyclerView. It has the ab
4 min read
ProgressBar in Android Progress Bar are used as loading indicators in android applications. These are generally used when the application is loading the data from the server or database. There are different types of progress bars used within the android application as loading indicators. In this article, we will take a lo
3 min read