I know that in Java, it is possible to do the following:
boolean condition = true;
for(int i=0; i<array.length && condition; i++){
}
If the condition is false, the for loop stops, but, how to do the same in Kotlin?
You can also use the below approach for the conditional for loop.
(0..array.length).takeWhile {
condition
}.forEach {
// do something with `it (index)`
}
fun checkCondition(){
val condition=true
outerloop@for(i in array.indices) {
if(array[i]!=condition){
condition=false
break@outerloop
}
}
return condition
}