why use do while?
Posted: Fri Jun 29, 2007 10:51 am
I have never used the do while loop in my entire history with PHP or any other language. I was just looking through HTML Purifier to try and make it less "magical" in my head and get a feeling for just how in the world it does what it does, and I came across this:
I can understand why he did this (because he put the comments in). Simply so he can break out of the do{} should he need to. But couldn't this have been accomplished just as easily by doing:
Is this simply a preference? Is there some advantage either way? What are some other uses for the do while syntax that made it worth putting in the language?
(Sorry to use your code for an example AC
)
Code: Select all
if (is_null($lexer)) { do {
// auto-detection algorithm
// once PHP DOM implements native line numbers, or we
// hack out something using XSLT, remove this stipulation
if ($config->get('Core', 'MaintainLineNumbers')) {
$lexer = 'DirectLex';
break;
}
if (version_compare(PHP_VERSION, "5", ">=") && // check for PHP5
class_exists('DOMDocument')) { // check for DOM support
$lexer = 'DOMLex';
} else {
$lexer = 'DirectLex';
}
} while(0); } // do..while so we can breakCode: Select all
if (is_null($lexer)) {
// auto-detection algorithm
// once PHP DOM implements native line numbers, or we
// hack out something using XSLT, remove this stipulation
if ($config->get('Core', 'MaintainLineNumbers')) {
$lexer = 'DirectLex';
break;
}
else {
if (version_compare(PHP_VERSION, "5", ">=") && // check for PHP5
class_exists('DOMDocument')) { // check for DOM support
$lexer = 'DOMLex';
} else {
$lexer = 'DirectLex';
}
}
} // do..while so we can break(Sorry to use your code for an example AC