「Kotlin入門」制御構文if式のサンプル
構文
val 変数名 = if(条件式) {
}
使用例1
val kk = if (bb < 32) {
"this is aa if"
} else {
"this is bb else"
}
val kk = if (bb < 32) {
"this is aa if"
} else {
"this is bb else"
}
val kk = if (bb < 32) { "this is aa if" } else { "this is bb else" }
使用例2
var target: Int
if (x > y) {
target = x
} else {
target = y
}
var target: Int
if (x > y) {
target = x
} else {
target = y
}
var target: Int if (x > y) { target = x } else { target = y }
使用例
val target = if (x > y) x else y