Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Types
  • Array
  • String
  • Functions
  • Collections
  • Oops
  • Android
  • Android Studio
  • Kotlin Android
  • Android Projects
  • Android Interview Questions
Open In App
Next Article:
Kotlin unlabelled continue
Next article icon

Kotlin unlabelled continue

Last Updated : 10 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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


 


Next Article
Kotlin unlabelled continue

P

Praveenruhil
Improve
Article Tags :
  • Kotlin
  • Kotlin Control-flow

Similar Reads

    Kotlin labelled continue
    In this article, we will learn how to use continue in Kotlin. While working with a loop 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.
    4 min read
    Kotlin Unlabelled break
    When we are working with loops and want to stop the execution of loop immediately if a certain condition is satisfied, in this case, we can use either break or return expression to exit from the loop. In this article, we will discuss learn how to use break expression to exit a loop. When break expre
    4 min read
    Kotlin labelled break
    While working with loops say you want to stop the execution of loop immediately if a certain condition is satisfied. In this case you can use either break or return expression to exit from the loop.In this article, we are going to learn how to use break expression to exit a loop. When break expressi
    4 min read
    Returns, Jumps and Labels in Kotlin
    Kotlin is a statically typed, general-purpose programming language developed by JetBrains, that has built world-class IDEs like IntelliJ IDEA, PhpStorm, Appcode, etc. It was first introduced by JetBrains in 2011 and a new language for the JVM. Kotlin is an object-oriented language, and a “better lan
    3 min read
    "lateinit" Variable in Kotlin
    In Kotlin, there are some tokens that cannot be used as identifiers for naming variables, etc. Such tokens are known as keywords. In simple words, keywords are reserved and have special meaning to the compiler, hence they can't be used as identifiers. For example, asbreakclasscontinuelateinit "latei
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences