Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php: what's the difference between while...endwhile; and while { // stuff here }

Tags:

What's the difference between

while (expression):  // do stuff  endwhile; 

and

while {  } 
like image 433
redconservatory Avatar asked Jan 10 '11 20:01

redconservatory


People also ask

What is while Endwhile?

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.

What is the difference between for loop and while loop in PHP?

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.

What is difference between while and for loop?

For is entry controlled loop. While is also entry controlled loop. used to obtain the result only when number of iterations is known.

What does Endwhile mean in pseudocode?

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.


2 Answers

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.

like image 111
Jeff Davis Avatar answered Oct 21 '22 21:10

Jeff Davis


There's no difference, it comes down to personal preference.

like image 45
S M Avatar answered Oct 21 '22 23:10

S M