05-Groovy-条件判断语句

简介: 05-Groovy-条件判断语句

前言

  • 本篇学习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. }
相关文章
|
XML 存储 开发工具
|
存储 Java API
阿里高级技术专家谈开源DDD框架:COLA4.1,分离架构和组件(下)
阿里高级技术专家谈开源DDD框架:COLA4.1,分离架构和组件(下)
11405 8
阿里高级技术专家谈开源DDD框架:COLA4.1,分离架构和组件(下)
如何修改NFS分享的目录?
如何修改NFS分享的目录?
403 2
|
Linux 数据安全/隐私保护
Linux中普通用户使用sudo命令提示lin is not in the sudoers file. This incident will be reported.
Linux中普通用户使用sudo命令提示lin is not in the sudoers file. This incident will be reported.
|
安全 JavaScript 前端开发
Nginx服务扫描漏洞修复
Nginx服务扫描漏洞修复
|
消息中间件 Linux
RabbitMQ最大连接数
RabbitMQ最大连接数
1081 0
软件开发常用之SpringBoot文件下载接口编写(下),Vue+SpringBoot文件上传下载预览,服务器默认上传是1M,可以调节,调节文件上传大小写法,图片预览,如何预览后下次还能看到,预览写法
软件开发常用之SpringBoot文件下载接口编写(下),Vue+SpringBoot文件上传下载预览,服务器默认上传是1M,可以调节,调节文件上传大小写法,图片预览,如何预览后下次还能看到,预览写法
|
Ubuntu 关系型数据库 MySQL
Ubuntu 安装 MySQL 5.7
Ubuntu 安装 MySQL 5.7
604 0
|
API Python JSON
使用django创建简单restful应用接口的步骤
【6月更文挑战第2天】本文简介使用Django创建API服务涉及安装djangorestframework,创建api应用,定义URL路由,编写视图和序列化器。这个过程展示了如何用Django Rest Framework构建JSON格式的API。
218 2