Loops are used when you want to execute a block of code a specified number of times, or while a specified condition is True.
while (condition) { // code to be executed }If the condition starts out as false, the statements won’t execute at all.
<?php $i = 0; while ($i<5) { echo '<br /> i = '. $i; $i++; } ?>- First it's declared a variable "$i" with the value of 0. The "while" statement checks the condition ($i<5), which it's True and permits the execution of block code inside the brackets. The "$i++" increments the value of "$i" by 1 each time the loop runs, and check again the condition. The loop will stop when the "$i" reach 5.
do { // code to be executed } while (condition)First will be executed the block of code, then checks the condition, and it will repeat the loop as long as the specified condition is TRUE.
<?php $x = 8; do { echo '<br /> x = '. $x; $x++; } while ($x<5) ?>- This example display "x = 8".
while (condition) { if(end_condition) break; // code to be executed }If the end_condition is True, the code after the "break" will not be executed at all, and the execution of "while" loop ends.
<?php $i = 0; while ($i<5) { if ($i==2) break; echo '<br /> i = '. $i; $i++; } ?>- Output:
<table><tr> <th>Title 1</th> <th>Title 2</th> </tr></table>
.some_class { line-height: 150%; }
document.getElementById("id_button").onclick = function(){ window.open("http://coursesweb.net/"); }
$ar_dir = scandir("dir_name"); var_export($ar_dir);