当数据比较庞大的时候,需要循环遍历某个数据的时候可用
for (int ab= 0;ab<10000;ab++){
if (ab ==7){//当找到7的时候,结束循环
Log.v("map","..ab ==7....11......"+ab);
break;
}else {
Log.v("map","......11..else...."+ab);
}
}
设定范围
for (int c=0;c<52;c++){ if (suiji<32||suiji>40){ suiji = Integer.parseInt(makeCheckCode()); Log.e("lgq","随机数==== "+suiji); }else { Log.e("lgq","随机数==333== "+suiji); break; } }
跳过
continue;
跳出当前的多重嵌套循环
int arr[][] ={{1,2,3},{4,5,6,7},{9}};
boolean found = false;
for(int i=0;i<arr.length&&!found;i++) {
for(intj=0;j<arr[i].length;j++){
System.out.println(“i=” + i + “,j=” + j);
if(arr[i][j] ==5) {
found =true;
break;
}
}
}