Wait in what language can't you use while true? Sorry I only use Python haha. Though I've been wanting to try a more low level one, Python feels like it has training wheels.
while true paired with break statements is considered bad coding practice in all languages with a few exceptions because it almost certainly can be rewritten as a for loop as a break statement suggests there is an exit condition in contrast to the „while true” suggesting it is an indefinite loop.
Just using while true with the intention of it being an actual infinite loop is totally fine tho. Also in Python people use a „while true” loop with a break statement to emulate a „do{}while()” loop and thats definitely better practice than repeating code so thats another exception and im sure theres more.
4
u/[deleted] Jun 09 '21
Ive had lost enough points in my life for writing while(1) that i just make a variable for it even if i wont use it.
foreverRun = True;
And tbh i dont have to make infinite loops too often outside of uni, most often theres something more logical to put there like
while(!Thread.Interrupted())
or sth