August 2017
Intermediate to advanced
440 pages
10h
English
The while loop repeats a block, while its conditional expression returns true:
while (condition) {
//code
}
There is also a do... while loop that repeats blocks as long as a conditional expression is returning true:
do {
//code
} while (condition)
Kotlin, as opposed to Java, can use variables declared inside the do... while loop as a condition:
do {
var found = false
//..
} while (found)
The main difference between the while and do... while loops is when a conditional expression is evaluated. A while loop checks the condition before code execution and if it is not true, the code won't be executed. On the other hand, a do... while loop first executes the body of the loop, and then evaluates the conditional expression, ...
Read now
Unlock full access