for (์ด๊ธฐํ; ์กฐ๊ฑด์; ์ฆ๊ฐ์) {
์กฐ๊ฑด์์ ๊ฒฐ๊ณผ๊ฐ ์ฐธ์ธ ๋์ ๋ฐ๋ณต์ ์ผ๋ก ์คํํ๊ณ ์ ํ๋ ๋ฌธ์ฅ;
}
์คํ ์์
์กฐ๊ฑด์ ์ด ์ฐธ์ผ ๊ฒฝ์ฐ ๋ฌธ์ฅ ์ํ
์กฐ๊ฑด์์ด ๊ฑฐ์ง์ด ๋ ๋ ๊น์ง ๋ฐ๋ณต
class Control3_1 {
public static void main(String[] args) {
int i = 0;
for (i = 0; i < 5; i++) {
System.out.println("for ๋ฌธ์ด " + (i + 1) + "๋ฒ์งธ ๋ฐ๋ณต ์คํ์ค์
๋๋ค.");
}
System.out.println("for ๋ฌธ์ด ์ข
๋ฃ๋ ํ ๋ณ์ i์ ๊ฐ์ " + i + "์
๋๋ค.");
}
}
class Control3_2 {
public static void main(String[] args) {
// 1๋ฒ
for (int i = 1; i <= 10; i = i * 2) {
System.out.println("1๋ฒ i๋ ํ์ฌ " + (i) + "์
๋๋ค.");
}
System.out.println();
// 2๋ฒ
for (int i = 10; i >= 1; i--) {
System.out.println("2๋ฒ i๋ ํ์ฌ " + (i) + "์
๋๋ค.");
}
}
}
class Control3_3 {
public static void main(String[] args) {
// ์ด๊ธฐํ ์ ๋ณ์ 2๊ฐ ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค. ๋จ, ํ์
์ด ๊ฐ์์ผ ํ๋ค.
for (int i = 1, j = 10; i <= 10; i++, j--) {
System.out.println("i๋ ํ์ฌ " + (i) + "์
๋๋ค.");
System.out.println("j๋ ํ์ฌ " + (j) + "์
๋๋ค.");
}
System.out.println();
// ์ด๋ ๊ฒ ๋ณ์ 2๊ฐ๋ฅผ ์ฌ์ฉํ์ฌ ์กฐ๊ฑด์์ ๊ตฌ์ฑํ ์ ์์ต๋๋ค.
for (int k = 1, t = 10; k <= 10 && t > 2; k++, t--) {
System.out.println("k๋ ํ์ฌ " + (k) + "์
๋๋ค.");
System.out.println("t๋ ํ์ฌ " + (t) + "์
๋๋ค.");
}
}
}
for (์ด๊ธฐํ; ์กฐ๊ฑด์1; ์ฆ๊ฐ์) {
์กฐ๊ฑด์1์ ๊ฒฐ๊ณผ๊ฐ ์ฐธ์ธ ๋์ ๋ฐ๋ณต์ ์ผ๋ก ์คํํ๊ณ ์ ํ๋ ๋ฌธ์ฅ;
for (์ด๊ธฐํ; ์กฐ๊ฑด์2; ์ฆ๊ฐ์) {
์กฐ๊ฑด์2์ ๊ฒฐ๊ณผ๊ฐ ์ฐธ์ธ ๋์ ๋ฐ๋ณต์ ์ผ๋ก ์คํํ๊ณ ์ ํ๋ ๋ฌธ์ฅ;
}
}
class Control3_4 {
public static void main(String[] args) {
for (int i = 2; i < 10; i++) {
System.out.println(i + "๋จ ์์ํฉ๋๋ค.");
for (int j = 1; j < 10; j++) {
System.out.println("j๋ ํ์ฌ " + (j) + "์
๋๋ค.");
System.out.println(i + "*" + j + "=" + (i * j));
}
}
}
}
for (ํ์
๋ณ์์ด๋ฆ : ๋ฐฐ์ด or ์ปฌ๋ ์
) {
๋ฐฐ์ด or ์ปฌ๋ ์
์ ๊ธธ์ด๋งํผ ๋ฐ๋ณต์ ์ผ๋ก ์คํํ๊ณ ์ ํ๋ ๋ฌธ์ฅ;
}
class Control3_5 {
public static void main(String[] args) {
int[] arr = new int[]{1, 2, 3, 4, 5};
for (int e : arr) {
System.out.print(e + " ");
}
}
}