}
for (int i = 1; i <= 10; i++) {
System.out.println("i = " + i);
}
run:
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
i = 8
i = 9
i = 10
for (int n = 10; n > 0; n–) {
System.out.println("n= " + n);
}
run:
n= 10
n= 9
n= 8
n= 7
n= 6
n= 5
n= 4
n= 3
n= 2
n= 1
int a, b;
for (a = 1, b = 4; a < b; a++, b–) {
System.out.println("a = " + a);
System.out.println("b = " + b);
}
run:
a = 1
b = 4
a = 2
b = 3
Циклы while. Синтаксис циклической конструкции while выглядит так:
while (БулевскоеВыражение)
Инструкция;
int n = 5;
while (n > 0) {
System.out.println("while " + n);
n–;
}
run:
while 5
while 4