Locked lesson.
About this lesson
In this lesson, we introduce Loops and explain how While and Do While work.
Exercise files
Download this lesson’s related exercise files.
36 - Loops While Loops.docx57.7 KB 36 - Loops While Loops SOLUTION.docx
58.8 KB
Quick reference
Loops: While Loops
While loops allow you to loop through code WHILE a condition is true.
When to use
Use them to loop through code.
Instructions
While Loop:
int x = 1;
while(x <= 10)
{
Console.WriteLine(x);
x++;
}
Do While Loop:
int x = 1;
do
{
Console.WriteLine(x);
x++;
} while(x <=10);
Hints & tips
- While loops continue looping WHILE a condition is true.
- You can use a regular While loop or a Do While loop as needed.
Lesson notes are only available for subscribers.