3 kotlin when 循环
相比于Java,Android中的while,kotlin的when更强大,可以直接给变量赋值
var level = 26when (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 = nullwhen (obj) {is Int -> println("obj是整形类型")is String -> println("obj是字符串类型")is Boolean -> println("obj是boolean")else -> println("Unknown type")}//while do-while forprintln("循环便利店。。。。 ")var count = 5while (count > 0) {println("1:$count")count--}//do -whilecount = 5do {println("2 $count")count--} while (count > 0)
喜欢可以加Q群号:874826112,一起学习,成长,交流工作经验,
记得要点赞,评论哦😯;
简书: /u/88db5f15770d
csdn:/beyondforme
掘金:https://juejin.im/user/5e09a9e86fb9a016271294a7