while loop iterates a part of the code until the given condition fails. This is an entry controlled loop. While loop is recommended to use if the condition depends on the user or not known In advance. Let’s see a simple example of while loop.


C# While loop example:


C# nested while loop:

Nested while loop is almost similar to nested for loop. We can use while loop inside a while loop. The inner will execute n number of time for each iteration of outer loop.

C#  Nested While loop Example:


C# infinite while loop example:

If we put a condition in while loop that never fails then the loop becomes an infinite loop .

Pin It on Pinterest

Share This