Intro to loops in CSharp
In this article you will get an introduction to loops in CSharp. Loops are a concept which allows us to call code recursively, as long as a condition is fulfilled. Let’s assume that we work at the office and have to do the same tasks all the time. “The next please.”. “Please fill this, that and that.” “Thank you and have a nice day”. “The next request”. So now we have a situation that we shout “the next please” until no one reacts. So we could make our work super easy and automate the whole thing with a loop. This loop should play our recording and always wait for the customer to fill the field. Pretty simple, right? Something like this will be discussed in the next articles.
There are different types of loops. Head-controlled (pre-condition) loops are the loops that first ask whether a condition is met and then run the code in the body. Examples of this are For and While loops. Foot-controlled (post-condition) loops are the loops that first run the code in the body and then check whether the condition is met. This can be solved with a Do While loop. In the next articles, we will discuss these different types of loops.