Kotlin do-while loop Last Updated : 24 May, 2025 Comments Improve Suggest changes Like Article Like Report Like Java, the do-while loop is a control flow statement that executes a block of code at least once without checking the condition, and then repeatedly executes the block, or not, depending on a Boolean condition at the end of the do-while block. It contrasts with the while loop because the while loop executes the block only when the condition becomes true, but the do-while loop executes the code first, and then the expression or test condition is evaluated. do-while loop working - First of all, the statements within the block are executed, and then the condition is evaluated. If the condition is true, the block of code is executed again. The process of execution of the code block is repeated as long as the expression evaluates to true. If the expression becomes false, the loop terminates and transfers control to the statement next to the do-while loop. It is also known as a post-test loop because it checks the condition after the block is executed. Syntaxdo { // code to run}while(condition)FlowchartKotlin program to find the factorial of a number using a do-while loop Kotlin fun main(args: Array<String>) { var number = 6 var factorial = 1 do { factorial *= number number-- }while(number > 0) println("Factorial of 6 is $factorial") } OutputFactorial of 6 is 720 Kotlin program to print a table of 2 using a do-while loop Kotlin fun main(args: Array<String>) { var num = 2 var i = 1 do { println("$num * $i = "+ num * i) i++ }while(i <= 10) } Output2 * 1 = 22 * 2 = 42 * 3 = 62 * 4 = 82 * 5 = 102 * 6 = 122 * 7 = 142 * 8 = 162 * 9 = 182 * 10 = 20 Comment More info P Praveenruhil Follow Improve Article Tags : Kotlin Kotlin Control-flow Explore Kotlin Tutorial 4 min read OverviewIntroduction to Kotlin 4 min read Kotlin Environment setup for Command Line 2 min read Kotlin Environment setup with Intellij IDEA 2 min read Hello World program in Kotlin 2 min read BasicsKotlin Data Types 3 min read Kotlin Variables 2 min read Kotlin Operators 4 min read Kotlin Standard Input/Output 4 min read Kotlin Type Conversion 2 min read Kotlin Expression, Statement and Block 4 min read Control FlowKotlin if-else expression 4 min read Kotlin while loop 2 min read Kotlin do-while loop 2 min read Kotlin for loop 4 min read Kotlin when expression 6 min read Kotlin Unlabelled break 4 min read Kotlin labelled continue 4 min read Array & StringKotlin Array 6 min read Kotlin String 4 min read FunctionsKotlin functions 7 min read Kotlin Default and Named argument 7 min read Kotlin Recursion 3 min read Kotlin Tail Recursion 2 min read Kotlin Lambdas Expressions and Anonymous Functions 6 min read Kotlin Inline Functions 5 min read Kotlin infix function notation 5 min read Kotlin Higher-Order Functions 6 min read CollectionsKotlin Collections 6 min read Kotlin list : Arraylist 6 min read Kotlin list : listOf() 7 min read Kotlin Set : setOf() 4 min read Kotlin hashSetOf() 4 min read Kotlin Map : mapOf() 5 min read Kotlin Hashmap 7 min read OOPs ConceptKotlin Class and Objects 4 min read Kotlin Nested class and Inner class 3 min read Kotlin Setters and Getters 4 min read Kotlin Class Properties and Custom Accessors 3 min read Kotlin Constructor 6 min read Kotlin Visibility Modifiers 6 min read Kotlin Inheritance 10 min read Kotlin Interfaces 7 min read Kotlin Data Classes 3 min read Kotlin Sealed Classes 4 min read Kotlin Abstract class 5 min read Enum Classes in Kotlin 4 min read Kotlin extension function 4 min read Kotlin generics 6 min read Exception HandlingKotlin Exception Handling - try, catch, throw and finally 5 min read Kotlin Nested try block and multiple catch block 3 min read Null SafetyKotlin Null Safety 7 min read Kotlin Type Checking and Smart Casting 3 min read Kotlin Explicit Type Casting 3 min read Like