Kong Eunho

1.2 연산자와 제어문

2025년 09월 07일 22시
카테고리 - TIL, flutter, 1_Dart_기초


1.2.1 연산자

연산자(Operators) : 변수나 값에 대해 특정 연산을 수행하는 기호.

① 산술 연산자 : +, -, *, /, %(나머지), ~/(몫)

② 관계 연산자 : ==, !=, >, >=, <, <=

③ 논리 연산자 : &&, ||, !

④ 대입 연산자 : =, +=, -=, *=, /=

1.2.2 제어문

제어문(Control Flow Statements) : 프로그램의 실행 흐름을 제어하는 문법.

① 조건문 : if, else if, else

int score = 85;
if (score >= 90) {
    print("A");
} else if (score >= 80) {
    print("B");
} else {
    print("C");
}

② 반복문 : for, while, do~while

for (int i = 0; i < 5; i++) {
    print("$i");
}
int i = 0;
while (i < 5) {
    print("$i");
    i++;
}

③ switch문 : 여러 값 중 하나를 선택하여 실행.

String fruit = "apple";
switch (fruit) {
  case "apple":
    print("사과");
    break;
  case "banana":
    print("바나나");
    break;
  default:
    print("기타 과일");
}
◀ 이전 글 TIL, flutter, 1_Dart_기초
1.1 변수와 자료형
2025-09-04
목록으로 다음 글 ▶ TIL, flutter, 1_Dart_기초
1.3 함수와 객체지향 프로그래밍
2025-09-07