3 kotlin when 循环
相比于Java,Android中的while,kotlin的when更强大,可以直接给变量赋值
var level = 26
when (level) {
26, 27 -> {
println("android Oreo")
}
24, 25 -> println("android nougat")
23 -> {
println("android mars")
}
else -> {
println("android 5一下")
}
}
//when 可以赋值
var content33 = when (level) {
26, 27 -> "andoird oreo"
else -> "android 5yixia"
}
println("$content33")
// when is 判断
var obj = null
when (obj) {
is Int -> println("obj是整形类型")
is String -> println("obj是字符串类型")
is Boolean -> println("obj是boolean")
else -> println("Unknown type")
}
//while do-while for
println("循环便利店。。。。 ")
var count = 5
while (count > 0) {
println("1:$count")
count--
}
//do -while
count = 5
do {
println("2 $count")
count--
} while (count > 0)
image
喜欢可以加Q群号:874826112,一起学习,成长,交流工作经验,
记得要点赞,评论哦😯;
简书: https://www.jianshu.com/u/88db5f15770d
网友评论