loops in C#
Loops repeat action so you don't have to write same logic again and again. loops helps to execute a line of code repeatedly until it reaches the defined condition. There are various loops in C# programming; i.e., While Loop, Do While loop, For loop, Foreach loop. Let's try to use each of them for a simple example. Let's understand the loop one by one with example. While Loop While loop checks the condition first and then executes the defined line of code, if the condition is true and keeps on executing as long as the condition is true. If the condition is false, it will get out of the while loop. Below we have example to demonstrate the while loop We have defined a static integer array of length 3. We need to print all the items present in the defined array. While loop will continue to print as long as defined var and whileInt is less than the length of int array as whileInt will go on increments of 1, each time the loop executes it. DoWhile Loop