Python While True creates an infinite loop and in other languages that use while
The base structure of that loop in Python:
While "condition" :
Python while loop is a conditional statement that runs as long as an expression evaluates to true. If while loop expression always evaluates to true. Therefore, the while loop will run every time.
It makes an infinite loop that only exits when you expressly break the loop. For example:-
i = 0
i += 1
if i == 5:
Note: If condition is true, It gonna create an infinite loop.
Q: In Python, is “while True:” bad coding style?
Answer: That’s very debatable,
while (true) is not a good idea because it makes it hard to maintain this code.
But that’s not bad since you may not always know the exit condition when you setup the loop or may have multiple exit conditions. However it does require more care to prevent an infinite loop.
Q: What does “while True” mean in Python?
True means loop forever.
The while loop will run as long as the conditional expression evaluates to
True always evaluates to
True, the loop will run indefinitely, until something within the loop
Do comment if you have any doubts and suggestions on this tutorial.
Note: This example (Project) is developed in PyCharm 2020.1 (Community Edition)
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
All Python Programs code are in Python 3, so it may change its different from python 2 or upgraded versions.