如何在Kotlin中使多条件循环 [英] How to make multiconditional for loop in kotlin
本文介绍了如何在Kotlin中使多条件循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Java中:
for(int j = 0; j < 6 && j < ((int)abc[j] & 0xff); j++) {
// ...
}
我们如何在Kotlin中进行此循环?
How we can make this loop in Kotlin?
推荐答案
我建议使用更实用的方法,例如
I'd suggest to use a more functional approach like
(0..5).takeWhile {
it < (abc[it].toInt() and 0xff) // or `as Int` if array is not numeric
}.forEach {
// do something with `it`
}
这篇关于如何在Kotlin中使多条件循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文