logoRawon_Log
홈블로그소개

Built with Next.js, Bun, Tailwind CSS and Shadcn/UI

Mobile

Dart 프로그래밍 가이드(조건문과 반복문)

Rawon
2025년 8월 29일
목차
Dart 프로그래밍 가이드
2. 조건문과 반복문
2.1 조건문
if-else문
switch문
2.2 반복문
for 반복문
for-in 반복문
while 반복문
do-while 반복문

목차

Dart 프로그래밍 가이드
2. 조건문과 반복문
2.1 조건문
if-else문
switch문
2.2 반복문
for 반복문
for-in 반복문
while 반복문
do-while 반복문

Dart 프로그래밍 가이드

목 차

  1. 변수와 타입
  2. 조건문과 반복문
  3. 함수
  4. 함수형 프로그래밍
  5. 객체지향 프로그래밍
  6. Enum
  7. Dart 3.0 업데이트 내용
  8. 비동기 프로그래밍

2. 조건문과 반복문

2.1 조건문

if-else문

dart
if (score >= 90) {
  print('A학점');
} else if (score >= 80) {
  print('B학점');
} else {
  print('C학점 이하');
}

switch문

dart
switch (day % 7) {
  case 0:
    print('일요일');
    break;
  case 1:
    print('월요일');
    break;
  default:
    print('기타');
    break;
}

2.2 반복문

for 반복문

dart
for (int i = 0; i < 10; i++) {
  print(i);
}
// 0 1 2 3 4 5 6 7 8 9

// continue 활용
for (int i = 0; i < 10; i++) {
  if (i == 5) continue;  // 5일 때 건너뛰기
  print(i);  // 0 1 2 3 4 6 7 8 9
}

for-in 반복문

dart
List<int> numbers = [1, 2, 3, 4, 5, 6];
for (int number in numbers) {
  print(number);  // 1 2 3 4 5 6 
}

while 반복문

  • 조건을 먼저 확인하고 반복문 실행
dart
int total = 0;
while (total < 10) {
  total += 1;
  if (total == 5) {
    break;  // 반복문 종료
  }
}
print(total); // 5

do-while 반복문

dart
int total = 0;
do {
  total += 1;
} while (total < 10);
// 최소 1회 실행 보장

이 링크를 통해 구매하시면 제가 수익을 받을 수 있어요. 🤗

https://inf.run/ZC6AE