Python Infinite while loop


Infinite while loop

If the condition is given in the while loop, it never becomes hostile, or the condition never becomes unsatisfied, then the while loop will never end, and it turns into the infinite while loop.

Remember- When the while loop condition never goes wrong or evaluates to False, then it will have an infinite loop, which is a loop that never ends (in theory) without external arbitration.
The loop won't stop until you touch 'Ctrl+C.'
An infinite while loop might be beneficial in client/server programming where the server necessitates to run constantly so that client programs can interact with it as and when needed.
An infinite while loop leads to a while loop where the while condition never goes wrong or evaluates to false. When a condition never goes false, the program enters the loop and continues repeating that same piece of code repeatedly, and the loop never terminates.

Some rules to remember:-

  • The loop should be written using a while keyword (accompanied by a space).
  • The condition to conclude if the loop will stay running or not depends on its truth value (True or False ).
  • The condition to decide if the loop will stay running depends on its truth value (True or False ).
  • Put a colon (:) at the finish of the first line.
  • The order of statements will be replicated. This code is called the "body" of the loop, and it needs to be ordered. When a statement is not ordered, it will not be viewed as part of the loop.

Example:

n = 1 x='Knowledge2life' while n > 0: n += 1 print(x)

OUTPUT:

(Infinite) Knowledge2life