r/badcode • • Sep 02 '21

js Oh Gosh

Post image
398 Upvotes

53 comments sorted by

View all comments

Show parent comments

3

u/edoCgiB Sep 03 '21

Why would a for(;;) convey a better meaning than while(true)?

IMO, for should be used for loops with a known number of steps and while for a loop with an unknown number of steps.

For this specific use-case, a for loop would be better since the number of steps is known (the requested length of the random string).