package com.study.javastudy.study;
public class ForExam {
public static void main(String[] args) {
int total = 0;
// for (int i = 1; i <= 100; i++) {
// if(i % 2 != 0) { // 홀수일 때
// continue; // 아래식을 계속 수행하라
// }
// total = total + i;
// }
// System.out.println(total); // 2550
for (int i = 1; i <= 100; i++) {
total = total + i;
if(i == 50) { // i가 50일 때
break; // 멈춰라
}
}
System.out.println(total); // 1275
}
}
for문
2024. 1. 27. 11:15