Last active
February 1, 2022 09:59
-
-
Save ghasemdev/aa6b6c20e3424f36fccb873d47a9c1ff to your computer and use it in GitHub Desktop.
Repeat loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Jumps.BREAK | |
import Jumps.CONTINUE | |
enum class Jumps { BREAK, CONTINUE } | |
inline fun repeat(action: (index: Int) -> Any) { | |
var counter = 0 | |
loop@ while (true) { | |
val result = action(counter) | |
if (result == BREAK) break@loop | |
counter++ | |
} | |
} | |
fun main() { | |
repeat { | |
if (it == 2) return@repeat CONTINUE | |
if (it == 5) return@repeat BREAK | |
println(it) | |
Thread.sleep(100) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment