前言
- 本篇学习if和switch语句
if语句
- if ...else...
1. // if条件语句 2. def age = 28 3. if (age >= 30) { 4. println("${age}岁,不小了,该找女票了") 5. } else { 6. println("还小呢,继续玩,才${age}岁") 7. }
- if ... else if ...else..
1. def age = 28 2. if (age >= 30) { 3. println("${age}岁,不小了,该找女票了") 4. } else if (age < 28 && age > 22) { 5. println("还小呢,继续玩,才${age}岁") 6. }else { 7. println("${age}尴尬的年纪") 8. }
switch语句
1. // switch语句 2. 3. def int age = 28 4. switch (age) { 5. case { 0 < age && age < 6 }: 6. println('在家打酱油呢') 7. break 8. case { 6 < age && age <= 22 }: 9. println('好好学习吧') 10. break 11. case { 22 < age && age <= 28 }: 12. println('工作搬砖ing') 13. break 14. case { 28 < age && age <= 30 }: 15. println('赶紧相亲吧') 16. break 17. case { 30 < age }: 18. println('放弃了,自己过吧!!!') 19. break 20. default: 21. println('想躺平!') 22. 23. }