dart (flutter) 문법 - 제어문. if, for, forEach, switch
- if 문.
if (isRaining()) {
you.bringRainCoat();
} else if (isSnowing()) {
you.wearJacket();
} else {
car.putTopDown();
}
- for, forEach 문.
var message = StringBuffer('Dart is fun');
for (var i = 0; i < 5; i++) {
message.write('!');
}
for (final candidate in candidates) {
candidate.interview();
}
var collection = [1, 2, 3];
collection.forEach(print); // 1 2 3
- while, do while 문.
while (!isDone()) {
doSomething();
}
do {
printLine();
} while (!atEndOfPage());
- switch 문.
test() {
var command = 'OPEN';
switch (command) {
case 'OPEN':
executeOpen();
break;
default:
executeUnknown();
}
}
참고.
https://dart.dev/guides/language/language-tour#control-flow-statements
댓글
댓글 쓰기