while loop in Kotlin

If you are from C or Java background, then the syntax of while loop will be familiar to you. while loop evaluates the condition before executing the statements present inside its body.

Syntax of while loop

while(condition){
   //code to be executed when condition is true
}

Flowchart of while loop

Flowchart of while loop

Example of while loop

fun main(args: Array<String>){
   var i = 1
   while(i<=10){
      println(3*i)
      i++
   }
}

Output

3
6
9
12
15
18
21
24
27
30