r/programminghorror • • Jun 09 '21

Javascript "Coding is like poetry" The code:

Post image
6.5k Upvotes

146 comments sorted by

View all comments

Show parent comments

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

2

u/BlueBox32 Jun 10 '21

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.

1

u/[deleted] Jun 10 '21

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.

2

u/BlueBox32 Jun 10 '21

Right that actually makes a lot of sense, I plan to get started on something big tomorrow(at least by my standards) so I'll keep that in mind.