07-20-2023, 06:37 AM
I am trying to have multiple statements for one condition. For example: this is a sample code for when statement.
when (x) {
1 -> print("x == 1")
2 -> print("x == 2")
else -> { // Note the block
print("x is neither 1 nor 2")
}
}
When x is 1, I also want to have an extra statement like x += 10, how can I do it?
when (x) {
1 -> print("x == 1")
2 -> print("x == 2")
else -> { // Note the block
print("x is neither 1 nor 2")
}
}
When x is 1, I also want to have an extra statement like x += 10, how can I do it?