31 lines
573 B
Plaintext
31 lines
573 B
Plaintext
If the same logic is needed for both instances, then:
|
|
|
|
* in an `if` structure they should be combined
|
|
|
|
[source,kotlin,diff-id=1,diff-type=compliant]
|
|
----
|
|
if ((a >= 0 && a < 10) || (a >= 20 && a < 50)) {
|
|
doFirstThing()
|
|
doTheThing()
|
|
}
|
|
else if (a >= 10 && a < 20) {
|
|
doTheOtherThing()
|
|
}
|
|
else {
|
|
doTheRest()
|
|
}
|
|
----
|
|
|
|
* for a `when`, the values should be put together in the branch expression list.
|
|
|
|
[source,kotlin,diff-id=2,diff-type=compliant]
|
|
----
|
|
when (x) {
|
|
1, 3 -> {
|
|
doFirstThing()
|
|
doSomething()
|
|
}
|
|
2 -> doSomethingDifferent()
|
|
else -> doTheRest()
|
|
}
|
|
---- |