Android – Kotlin – 在进程中间停止
在没有break
情况下,是否有任何方法可以停止在Kotlin中循环?
例如:
for (item in items) { for (item2 in arrRealmTemp ) { if (item.MKT == item2.MKT && item.UPC == item2.UPC ) { // I want to stop this (the inner for only ) here } } }
- Android + Kotlin – 项目不再建设
- 更改导航抽屉项目颜色过滤器也改变了使用相同的图像ID的imageView
- 协议缓冲gradle支持Kotlin Android不工作?
- 原生Android应用程序的定义是什么?
- 安装Kotlin Android项目失败INSTALL_FAILED_DEXOPT
您可以按以下方式使用标签。
loop@ for (i in 1..100) { for (j in 1..100) { if (...) break@loop } }
在Kotlin中,您可以使用标签并continue
确保继续for循环的下一次迭代:
loop@ for (item in items) { for (item2 in arrRealmTemp ) { if (item.MKT == item2.MKT && item.UPC == item2.UPC ) { continue@loop } } }