Loop သည် code တစ်ပိုင်းကို ထပ်ခါထပ်ခါ run လုပ်ရန်သုံးပါတယ်။ List ထဲက data တွေပြရန်၊ total တွက်ရန်၊ search/filter လုပ်ရန် အရေးကြီးပါတယ်။
dart
void main() {
List<int> prices = [3000, 5000, 7000];
int total = 0;
for (final price in prices) {
total += price;
}
print('Total: $total');
int count = 1;
while (count <= 3) {
print('Attempt $count');
count++;
}
}for-in loop က List ထဲက price တစ်ခုချင်းစီကိုယူပြီး total ထဲပေါင်းထည့်ပါတယ်။ while loop က condition မှန်နေသရွေ့ run လုပ်ပြီး count++ က count ကို 1 တိုးပါတယ်။
You should see
Total: 15000 Attempt 1 Attempt 2 Attempt 3