Day 30 — While Loops

Loops are an important part of computer programming since they have the ability to save time when running a specific function over and over. For example, a loop can be used to go through a list of data and gather information for the programmer in a few simple lines of code. There are a few different types of loops in C#. I will be talking about a while loop.

A while loop is very simple to use and in my opinion one of the easier loops to implement. It basically iterates through whatever code is placed inside of it, as long as certain conditions are met. A simple form of this is usually written out like so:

int i = 0;

while (i < 5) {




The above example allows the loop to run 5 times. The code will run, iterate i by 1, and the process will repeat again until the i value reaches 5. At that point, the loop ends.

This is an example of me using a while loop to control the flow of the entire game logic of my blackjack game. A counter is used at the end of the body to continue the iteration.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.