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.
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.