Infinite For Loop Example in C#

Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 53
for (int i = 0;  i < 1;i++,i--)
Console.WriteLine("Infinite Loop");

The initial value of i is 0; Then 0 is checked with 1 which is smaller and the condition satisfies. The inner statement inside the loop executed i.e. "Infinite Loop" printed. Then the value of i is incremented to 1. But because of i--, the value got decremented to 0. And the process continues for ever.

Comments or Responses

Login to post response