Loop is a way to run a block of code over and over. Whenever you need to print items from a list, count things, or process data, skipping the loop is like walking from Tokyo to Osaka instead of taking the train — technically possible, but needlessly exhausting.
csharp
// for loop: အကြိမ်အရေအတွက် သိတဲ့အခါ သုံးလို့ကောင်းပါတယ်
for (int i = 1; i <= 3; i++)
{
Console.WriteLine($"Step {i}");
}
// foreach loop: collection ထဲက item တိုင်းကို သွားချင်တဲ့အခါ သုံးပါတယ်
string[] languages = { "C#", "Java", "PHP" };
foreach (string language in languages)
{
Console.WriteLine(language);
}What this code does
forloop starts ati = 1and keeps running as long asi <= 3stays true.i++increasesiby 1 after every pass through the loop.foreachgrabs each item in the array one by one and prints it.
You should see
Step 1 Step 2 Step 3 C# Java PHPInfo
⚠️ Common mistake
while loop, forgetting to update the condition can leave you with an infinite loop. Every time you write a loop, always ask yourself: "When does this actually stop?"