Kotlin Do While Loop

Do while loop, are executed first looping statements after that inside a while-statement condition is decided looping statement will execute or not. So this loop are provide guarantee to executes inside block of statements at least one time. When other condition is not change the flow of this loop (break,continue,return statements). We can define do-while loop using following syntax.

do{
//loop statement
//Modified terminating condition (optional)
}while(expression)

Kotlin Do While Loop

Do while loop, are executed first looping statements after that inside a while-statement condition is decided looping statement will execute or not. So this loop are provide guarantee to executes inside block of statements at least one time. When other condition is not change the flow of this loop (break,continue,return statements). We can define do-while loop using following syntax.

flowchart-while-loop
do{
//loop statement
//Modified terminating condition (optional)
}while(expression)

do and while is an keywords, body of loop is defined within the curly bracket {} . While statement is check expression result in form of boolean value. If that is true then repeatedly executed of body statement. Otherwise terminates the flow of loop execution. For example.

//example of do while loops
fun main(args: Array<String>) {
  
  var status=1;
  do{
    //loop statement here
    println("$status")

    status++; //modified value
  }while(status<=5) //terminate condition
}

Output

1
2
3
4
5

do and while is an keywords, body of loop is defined within the curly bracket {} . While statement is check expression result in form of boolean value. If that is true then repeatedly executed of body statement. Otherwise terminates the flow of loop execution. For example.

//example of do while loops
fun main(args: Array<String>) {
  
  var status=1;
  do{
    //loop statement here
    println("$status")

    status++; //modified value
  }while(status<=5) //terminate condition
}

Output

1
2
3
4
5


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved