October 2018
Intermediate to advanced
370 pages
9h 15m
English
A do while loop executes a block of code at least once, and then repeatedly executes the block (or not) depending on a given condition at the end of the block. This is a minor variation of the while loop. In do while, the body executes before the condition is verified, therefore executing the code block at least once:
fun main(args: Array<String>) { println("Do While loop") var j = 1 do { println(j) j++ } while( j < 5 ) }
In this example, variable j is initialized with value 1, the do block prints the value of j and increments it, while block verifies the condition. The loop will continues until the value of j is less than 5.
Read now
Unlock full access