Infinite Loop Example in Python

Posted by Rajnilari2015 under Python category on | Points: 40 | Views : 52
from System import *

class Program(object):
def Main(args):
i = 0
while i < 1:
Console.WriteLine("Infinite Loop")
i += 1
i -= 1

Main = staticmethod(Main)

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