Do..While Loop and Its Usage in Kotlin
Definition
- A Do..while loop is similar to while loop except that the condition will be checked after the block of code is executed.
- Like while loop, do while is a control flow statement that allows a particular code block to be executed repeatedly based on a given condition which returns a boolean value.
- The corresponding block of code is executed continuously until the condition fails or returns false.
Syntax
do {
Code to execute while the condition is true
} while ( condition );
Do..While Loop Example Program in Kotlin
// Do..While Loop in Kotlin Example Program
// Loop and Control Statements Kotlin Programs, Basic Kotlin Programs
fun main(args: Array<String>) {
var num1 = 0
do {
println(" Value : $num1")
num1++;
}while (num1<5)
}
Sample Output
Value : 0
Value : 1
Value : 2
Value : 3
Value : 4
Read More Articles
- Declare Variables In Kotlin
- Read Data Input using Scanner in Kotlin
- print and println Data Output in Kotlin
- Double Data type Usage and Type Conversion in Kotlin
- Arithmetic Operators (Mathematical Operators) in Kotlin
- Unary Operators (Sign, Inverts, Increment, and Decrement) in Kotlin
- Equality Operators (==, !=) and Referential equality Operators (===, !==) in Kotlin
- Printing Variables and Values in Kotlin
- Float Data type Usage and Type Conversion in Kotlin
- Long Data type Usage and Type Conversion in Kotlin
- Comparison Operators in Kotlin
- Byte Data type Usage and Type Conversion in Kotlin
- Is Operator (is and !is) in Kotlin
- In Operator (in and !in) in Kotlin
- Char Data type Usage and Type Conversion in Kotlin
- Read Data Input from Command Line in Kotlin
- Assignment Operators and Augmented Assignment Operators in Kotlin
- Indexed Access Operator [, ] in Kotlin
- Read String Data Input in Kotlin
- Short Data type Usage and Type Conversion in Kotlin
- Boolean Data type Usage and Type Conversion in Kotlin
- Logical Operators in Kotlin
- Elvis Operator (?:) in Kotlin
- Repeat and Its Usage in Kotlin
- Safe Call Operator (?.) in Kotlin