Ads by ProfitSence
Close

C# Do While Loop and Do While Nested Loop Examples

Last Updated on Wednesday 5th Oct 2022

Example 1 : Do While loop C#

			
					using System;
public class DoWhileExample {
  public static void Main(string[] args) {
    int i = 1;

    do {
      Console.WriteLine(i);
      i++;
    } while (i <= 10);

  }
}

			
	

OutPut

			
					1
2
3
4
5
6
7
8
9
10

			
	

Example 2 : Do While Nested loop C#

			
					using System;
public class DoWhileExample {
  public static void Main(string[] args) {
    int i = 1;
    do {
      int j = 1;
      do {
        Console.WriteLine(i + " " + j);
        j++;
      } while (j <= 3);
      i++;
    } while (i <= 3);
  }
}

			
	

OutPut

			
					1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

			
	

Example 3 : Do While Nested Loop Infinite C#

			
					using System;
public class WhileExample {
  public static void Main(string[] args) {
    do {
      Console.WriteLine("Infinite");
    } while (true);
  }
}

			
	

OutPut

			
					Infinite
Infinite
Infinite
Infinite
Infinite
Infinite
Infinite
Infinite
Infinite
Infinite
Infinite
Infinite
Infinite
...