Python infinite loop

An infinite loop is a loop that runs indefinitely and it only stops when there is an external intervention or when a break statement is found.

See the following loop:

CopiedCopy Code

i=1 
while i<=10: 
     print(i) 

The initial 'i' value 1 is displayed first, but it is never incremented to reach 10. Hence this loop will always display 1 and never terminates. Such a loop is called 'infinite loop'. An infinite loop is a loop that executes forever.

infinite loop example

CopiedCopy Code

while(True): 
   print("Hai")