Skip to content

Latest commit

 

History

History
115 lines (84 loc) · 1.34 KB

File metadata and controls

115 lines (84 loc) · 1.34 KB

Dart - Flow Control

조건문

int age = 20;

if (age >= 18) {
  print('성인입니다');
} else {
  print('미성년자입니다');
}

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



삼항 연산자

String result = (age >= 18) ? '성인' : '미성년자';



Switch

String grade = 'B';

switch (grade) {
  case 'A':
    print('최우수');
    break;
  case 'B':
    print('우수');
    break;
  default:
    print('기타');
}



Loops

for

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



for-in (컬렉션 순회)

List names = ['철수', '영희', '민수'];
for (var name in names) {
  print(name);
}



while

int i = 0;
while (i < 3) {
  print(i);
  i++;
}



do-while

int i = 0;
do {
  print(i);
  i++;
} while (i < 3);

문제

0부터 20까지의 숫자 중 짝수만 출력하되, 10이 넘으면 반복을 종료할 것.

  • while문을 사용할 것
  • continue와 break를 반드시 사용할 것



⛔ 흐름제어 키워드

  • break : 루프 또는 switch 종료
  • continue : 현재 반복 건너뛰고 다음 반복 진행
  • return : 함수 종료 및 값 반환

History

  • 250716 : 초안작성