Thuta Learning
BasicProgrammingbeginner

Loops

Relax. We'll talk through this in plain words — no textbook voice.

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

  • for loop starts at i = 1 and keeps running as long as i <= 3 stays true.
  • i++ increases i by 1 after every pass through the loop.
  • foreach grabs each item in the array one by one and prints it.
You should see
Step 1 Step 2 Step 3 C# Java PHP

Info

⚠️ 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?"

Loops | Thuta Learning