目录
一、while循环
循环三要素:
①循环变量的初值
②循环变量的判断
③循环变量的更新
while(循环条件){
循环操作语句
}
实例:
int i = 1 ; //循环变量的初值
while(i < 10){ //循环变量的判断
System.out.println( i );
i++; //循环变量的更新
}
二、do while循环
do{
循环操作;
}while(循环条件);
实例:
int a = 1, b = 10;
do{
b-=a;
a++;
}while(b--<0); //执行结果b=8;
三、for循环
for(表达式1;表达式2;表达式3){
循环语句;
}
实例:
int a = 5;
for(int i = 1;i < 5;i++){
a++;
}
四、Java程序的调试
1.设置断点(break point) 右键-Toggle Breakpoint / 双击
2.开启调试/单步调试 Debug step over-F6
3.观察变量 Window-showview-Other-Debug-Variables