What's the difference between
while (expression): // do stuff endwhile;
and
while { }
The WHILE - ENDWHILE statement defines a program loop. This statement can only be used inside a database procedure. The Boolean expression (boolean_expr) must evaluate to true or false. A Boolean expression can include comparison operators (' =',' >', and so on) and these logical operators: • AND.
Loops in PHP are used to execute the same block of code a specified number of times. PHP supports following four loop types. for − loops through a block of code a specified number of times. while − loops through a block of code if and as long as a specified condition is true.
For is entry controlled loop. While is also entry controlled loop. used to obtain the result only when number of iterations is known.
ENDWHILE CASE. A CASE construct indicates a multiway branch based on conditions that are mutually exclusive. Four keywords, CASE, OF, OTHERS, and ENDCASE, and conditions are used to indicate the various alternatives. The general form is: CASE expression OF condition 1 : sequence 1.
There is no functional difference.
In practical use I find that:
while (expression): // do stuff endwhile;
Is more readable for the designers when you are embedding php code within html. IE:
<? while ($cssClass = array_pop($array)): ?> <li class="<?=$cssClass?>"> <? endwhile; ?>
Whereas:
while { }
Is more readable within a php code block.
There's no difference, it comes down to personal preference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With