I am converting a large project to Kotlin. There have been numerous challenges. Me learning the new patterns of Kotlin is one of them. Hopefully there is a pattern I can use to resolve this one.
Here is the code I am attempting to achieve. But, continue
and break
are not valid in a when
statement.
while (!mStopped && c.moveToNext()) {
val itemType = c.getInt()
when (itemType) {
1, 2 -> {
doSomething()
if (condition)
continue
doSomethingElse()
}
}
doTheLastStuff()
}
This is a very cut-down version of the code. The original java code had 100's of lines inside the switch statements, and lots of continue
's and break
's.
What I am trying to achieve is to continue execution back at the while
statement. What is the pattern for doing this in Kotlin