Control Flow Statements in Dart
Control flow statements are used to control the flow of execution in a program. Dart supports if-else statements, switch statements, and loops such as for, while, and do-while loops.
void main() {
var x = 10;
if (x > 5) {
print('x is greater than 5');
} else {
print('x is less than or equal to 5');
}
var fruit = 'apple';
switch (fruit) {
case 'banana':
print('This is a banana');
break;
case 'apple':
print('This is an apple');
break;
default:
print('Unknown fruit');
}
for (var i = 0; i < 5; i++) {
print('i = $i');
}
var j = 0;
while (j < 5) {
print('j = $j');
j++;
}
}
No comments:
Post a Comment