this post was submitted on 30 Sep 2023
943 points (96.4% liked)

Programmer Humor

32048 readers
1531 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 11 months ago* (last edited 11 months ago)

I got an application that runs through a big calculation that has to pass several sanity checks along the way. If any check fails, the input parameters are tweaked and the calculation starts again from the top, iteratively approaching the ideal solution. Do-while is perfect for this.

It beats recursion in non-tail-call-optimized implementations (JavaScript...). And while this could be done just as well with a comon while loop plus a flag variable, I like the way the syntax of do-while naturally reads as, "Do [thing]. ... Did it work? No? Do it again".

I'd still argue it's redundant. If they got rid of it tomorrow I'd refactor and cope with no complaints. But as long as it's around, I like using it.