1. for 循环的结构:
for (initialization; condition; increment/decrement) { statement(s); }
2. for循环的例子:
(1)对于数组:
for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); }
(2)对于保存计数变量的循环: for (int i = 0; i < 10; i++) {
System.out.println(\"This is the \" + i + \"th time.\"); }
(3)根据逻辑判断实现循环: int count = 0; boolean stop = false; while (!stop) { count++; if (count >= 10) {
stop = true; }
System.out.println(\"This is the \" + count + \"th time.\"); }
(4)遍历Map:
for (Map.Entry 因篇幅问题不能全部显示,请点此查看更多更全内容