while loop က condition မှန်နေသရွေ့ code ကို ထပ်ခါထပ်ခါ run ပါတယ်။ ဘယ်နှစ်ကြိမ် run မလဲ မသေချာသေးတဲ့အခါ အသုံးဝင်ပါတယ်။ ဥပမာ user မှန်ကန်တဲ့ password ထည့်မချင်း မေးနေခြင်း၊ file ဆုံးမဆုံးဖတ်ခြင်း စတာတွေပါ။
c
#include <stdio.h>
int main() {
int i = 0;
while (i < 5) {
printf("%d
", i);
i++;
}
return 0;
}ပထမ i က 0 ဖြစ်ပါတယ်။ Loop တစ်ခါ run ပြီးတိုင်း i++ ကြောင့် 1 တိုးသွားပါတယ်။ i < 5 မမှန်တော့တဲ့အခါ loop ရပ်ပါတယ်။
You should see
0 1 2 3 4Info
Loop ထဲမှာ condition ကို false ဖြစ်စေမယ့် update ရှိရပါမယ်။ ဒီ example မှာ i++ ပါ။