When is a do-while the better choice over other types of loops? What are some common scenarios where its better than others?
I understand the function of a do-while,
I've used it before if I need to implement lots of conditional checks, for example processing an input form in php. Probably not the best practice, but it's more readable than many alternatives:
do {
if ( field1_is_invalid ) {
$err_msg = "field1 is invalid"; break;
}
if ( field2_is_invalid ) {
$err_msg = "field2 is invalid"; break;
}
.. check half a dozen more things ..
// Only executes if all checks succeed.
do_some_updates();
} while (false)
Also, I guess this isn't technically a loop. More like a way of avoiding using GOTO :)