I am new to kotlin and I want to make a switch that doesn't have a “break”. In java it would be like this:
switch (b){
case 3:
Log.d("int", "3");
case 2:
Log.d("int", "2");
case 1:
Log.d("int", "1");
}
And if b = 2, then it will print:
D / int: 2
D / int: 1
I want to do this in Kotlin without having to go through the same code for each case. In the Kotlin converter, the code output was that:
when (b) {
3 -> {
Log.d("int", "3")
Log.d("int", "2")
Log.d("int", "1")
}
2 -> {
Log.d("int", "2")
Log.d("int", "1")
}
1 -> Log.d("int", "1")
}
Is there any other way to do this? My actual code is much bigger than the one
yasin source
share