Kotlin While loop

while statement is used to repeat a task, checking the condition priorly for each iteration before executing the iterative block.

While Loop Example

while loop example using break statement

Kotlin do-while loop

Kotlin do-while loop is the same as while loop, except that the condition is not checked for the first time before executing the iterative block. Therefore it is guaranteed that the iterative block is executed at least once.

do-while example Kotlin program