иногда, основываясь на каком-то условии, он может захотеть прыгнуть (или двигаться вперед) на несколько шагов внутри цикла for,
как это сделать - kolin?
упрощенный вариант использования:
val datArray = arrayOf(1, 2, 3......)
/**
* start from the index to process some data, return how many data has been
consumed
*/
fun processData_1(startIndex: Int) : Int {
// process dataArray starting from the index of startIndex
// return the data it has processed
}
fun processData_2(startIndex: Int) : Int {
// process dataArray starting from the index of startIndex
// return the data it has processed
}
в Java это может быть:
for (int i=0; i<datArray.lenght-1; i++) {
int processed = processData_1(i);
i += processed; // jump a few steps for those have been processed, then start 2nd process
if (i<datArray.lenght-1) {
processed = processData_2(i);
i += processed;
}
}
Как это сделать в kotlin?
for(i in array.indices){
val processed = processData(i);
// todo
}