C# Loops

while Loop

Repeats a block as long as the condition is true:

Basic Structure:

while (condtion) {
  // code block
}
Loading...
Output:

do-while Loop

Runs the block once before checking the condition:

Basic Structure:

do {
  // code block
} while (condtion);
Loading...
Output:

for Loop

Ideal for counting or fixed number of iterations:

Basic Structure:

for (initialization; condition; updates) {
  // code block
}
Loading...
Output:

break Statement

Exits the loop entirely and does not finish the iterations even if the condition is still met:

Loading...
Output:

continue Statement

Skips the current loop iteration and goes to the next:

Loading...
Output:

Practice Prompt

What will this print?

Loading...
Output:

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic