How to create an infinite loop in C#?

An infinite loop is a loop that never terminates and repeats indefinitely.

Let us see an example to create an infinite loop in C#.


using System;
namespace Demo {
   class Program {
      static void Main(string[] args) {
         for (int a = 0; a < 50; a--) {
            Console.WriteLine("value : {0}", a);

Above, the loop executes until a < 50. The value of is set to 0 initially.

int a = 0;

The value of a decrements after each iteration since it is set to.


Therefore the value of a will never be above 50 and the condition a <50 will be true always. This will make the loop an infinite loop.