- if条件语句
if(布尔表达式1){
语句序列
}
else if(布尔表达式2)){
语句序列
}
else{
语句序列
}
- switch语句,应该有表达式和break以及default
int a = 1;
switch (a){
case 1:System.out.println(1);
break;
case 2:System.out.println(2);
break;
default:System.out.println(3);
}
- while循环语句
while(表达式){
语句序列
}
- do···while循环语句
do{
执行语句
}
while(表达式)
- for循环
for(表达式1; 表达式2; 表达式3){
执行语句
}
// 无限循环
for(;;){
执行语句
}
- foreach语句
for(元素变量x: 遍历对象){
引入x的java语句;
}
- break跳出循环
- continue跳出本次循环