Left Index

Kotlin do while loop

The do...while loop is similar to while loop with one key difference. The body of do...while loop is executed once before the test expression is checked.

package com.theitbulls.kotlinex

fun main(args: Array<String>) {
	var num1 = 1

	do {
		println("Num is: " + num1)
	} while (num1 <= 10)

The codes inside the body of do construct is executed once (without checking the num1 <= 10). Then, the condition is checked.