Groovy-3.流程控制

2019-06-02 12:57:01 浏览数 (1)

1.循环

1.1while
代码语言:javascript复制
while(condition) { 
   statement #1 
   statement #2 
   ... 
}
1.2.for
代码语言:javascript复制
for(variable declaration;expression;Increment) { 
   statement #1 
   statement #2 
   … 
}
1.3.for...in
代码语言:javascript复制
for(variable in range) { 
   statement #1 
   statement #2 
   … 
}
1.4.break 和 continue
  • break终止该层循环
  • continue结束本次迭代

2分支控制

2.1.if...else
代码语言:javascript复制
if(condition) { 
   statement #1 
   statement #2 
   ... 
} else if(condition) { 
   statement #3 
   statement #4 
} else { 
   statement #5 
   statement #6 
}
2.2.switch
代码语言:javascript复制
switch(expression) { 
   case expression #1: 
   statement #1 
   ... 
   case expression #2: 
   statement #2
   ... 
   case expression #N: 
   statement #N 
   ... 
   default: 
   statement #Default 
   ... 
}

0 人点赞