

It has three parts: an initializer, a condition, and an operation that takes place each time through the loop.Įach of these sections are separated by semicolons:

The C# do-while statement is quite analogous, except that in this case the loop must always be executed at least once, since the test is at the bottom of the loop: Since the loop is executed as long as the condition is true, it is possible that such a loop may never be executed at all, and of course, if you are not careful, that such a while loop will never be completed. All of the statements inside the braces are executed repeated as long as the condition is true.

Each of them provides ways for you to specify that a group of statements should be executed until some condition is satisfied. C# has four looping statements: while, do-while, for and for each.
