320x100
#1 for loop의 기본형태
가장 중요한 것은 for 옆에 기술되는
어떤 조건; 언제까지 실행?; 1회 루프 실행시 어디까지 할거야? {
과정;
}
이라고 판단 된다.
void main() {
// for loop
// 어떤 조건; 언제까지 실행?; 1회 루프 실행시, 어떻게 할거야?
for (int i = 0; i < 10; i++) {
print(i);
}
int total = 0;
List<int> numbers = [1,2,3,4,5,6];
for (int i=0; i < numbers.length; i++) {
total += numbers[i];
}
print(total);
// 21
// 초기화
print('init');
total = 0;
for (int number in numbers) {
print(number);
total += number;
};
print(total);
// 21
}
#2 while loop의 기본 형태
while loop의 포인트는
while(어떤 조건) {실행되는 내용}이다.
void main() {
// while loop
int total = 0;
// (어떤조건) {실행되는 내용}
while(total < 10) {
total += 1;
}
print(total);
// 10
// 초기화
total = 0;
print('init $total');
// init 0
}
void main() {
for (int i = 0; i < 10; i++){
if(i == 5){
continue;
}
print(i);
// 0부터 9까지 출력 되지만, 위의 if (i == 5)에 대한 실행문이 continue라
// 5는 출력 안됨
}
}
300x250
'개발일지 > 임시카테고리' 카테고리의 다른 글
python(파이썬) - 베스킨라빈스 31 게임 만들기 (0) | 2025.03.21 |
---|---|
dart - enum 사용해야하는 이유 (0) | 2025.03.21 |
Dart 기본문법 switch 문 기초 (0) | 2025.03.21 |
나를 위한 Dart 기본기 기초 문법 총모음 2 - Map, List, Set (0) | 2025.03.21 |
나를 위한 Dart 오퍼레이터 기본기 기초 문법 총모음 1 (0) | 2025.03.21 |