Loops in C#

What is an iteration?

In programming some problems require the repetition of some instructions.
A loop is a basic programming construct that allows repeated execution of instructions.
In this course, we will focus on while and for loops.

While Loop

One of the simplest and most commonly used loops is the "while" loop:

You must specify the three actions:


Write an algorithm/pseudocode for an application that uses a while loop display numbers from 0 to 9 in a List-box.

The C# code for this example is as follows:
		// Declare & Initialize the counter 
		int counter = 0; 
		// Execute the loop body while the loop condition is true
		while (counter <= 9) 
			lstNumbers.Items.Add("Number : " + counter);  // Display the counter value 
			counter++; 	// Increase the counter by 1
Here is how the output looks like:

For more details, please contact me here.
Date of last modification: March 17, 2019