You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let nb = 42
switch nb {
case 0: print("zero")
case 1, 2, 3: print("low numbers")
case 4...7, 8, 9: print("single digit")
case 10: print("double digits")
case 11...99: print("double digits")
case 100...999: print("triple digits")
default: print("four or more digits")
}
The resulting Kotlin is:
val nb = 42
when (nb) {
0 -> print("zero")
in 1, 2, 3 -> print("low numbers")
in 4 .. 7, 8, 9 -> print("single digit")
10 -> print("double digits")
11 .. 99 -> print("double digits")
100 .. 999 -> print("triple digits")
else -> print("four or more digits")
}
However it should be:
val nb = 42
when (nb) {
0 -> print("zero")
1, 2, 3 -> print("low numbers")
in 4 .. 7, 8, 9 -> print("single digit")
10 -> print("double digits")
in 11 .. 99 -> print("double digits")
in 100 .. 999 -> print("triple digits")
else -> print("four or more digits")
}
Note that the in prefix is correct in the case of expressions like 11...99
The text was updated successfully, but these errors were encountered:
When using this code Swift code:
The resulting Kotlin is:
However it should be:
Note that the
in
prefix is correct in the case of expressions like11...99
The text was updated successfully, but these errors were encountered: