Want to create interactive content? It’s easy in Genially!

Get started free

Loops in C# (For, While, Do-While)

Adam Wingell

Created on February 17, 2025

Start designing with a free template

Discover more than 1500 professional designs like these:

Transcript

Loops in C# (For, While, Do-While)

While Loop

Do-WhileLoop

For Loop

The For Loop

The for loop is used when you know how many times you want to iterate the code within it. The for loop consists of three statements seperated by semicolons. The 1st statement sets the initial variable, the 2nd statement is the condition that must become true before it can exit the loop, the 3rd statement increases the initial variable until it hits the condition set in statament 2.

While Loops

A While loop always loops until the becomes false. In the example shown you can see the initila value of i = 0, the while loop has a condition to run while is less than 5, within the while loop the program adds one to i every iteration until i = 5 then the condition is false and it breaks out the loop.

Do-While Loops

A Do-While loop is the same as a while loop in theory. The loop first starts with the a Do statements which tells the program to do this loop once, after the loop has iterated, the while statement then checks the condition and loops back to the do statement to go around again, checking the condition after each loop.