PHP has two “while†constructs, one if the code needs to run before the condition is checked:
and the other if if the code needs to run after the condition is checked:
But sometimes a portion of code needs to be executed before the condition is checked, and another portion after the condition is checked. Here is an example directly from the php ducomentation:
This is an easy problem that can be solved with an assignment in condition, it generates a warning but it does not break the code. Yet many times the operation to be performed before and after the condition check are more complicated and cannot be written in a single line (at least, not a single readable line).
IMHO Php lacks a “do { /*code*/ } while(condition) { /* code */ }†construct:
I opened an improvement request https://bugs.php.net/bug.php?id=65181 , feel free to share your ideas.