jeudi 3 mai 2018

Kotlin: replace 'cascade if' with 'when' comparing with other variables

I'm starting with Kotlin and I'm facing a problem. I have three constants (let's call them VAL_A, VAL_B and VAL_C) and I'm doing this assignation:

var variable = if (value < VAR_A) {
            valueA
        } else if (value <= VAR_B) {
            valueB
        } else if (value <= VAR_C) {
            valueC
        } else {
            valueD
        }

I want to use a when block instead of the if else, but I don't know how to do the value < VAR_A and the value > VAR_C ones.

Thank you and sorry abount my English!

Aucun commentaire:

Enregistrer un commentaire