Programming:PHP/do while loop

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Return to PHP.

[edit] The do while loop

The do while loop is similar in syntax and purpose to the while loop. The do/while loop construct moves the test that continues the loop to the end of the code block. The code is executed at least once, and then the condition is tested. For example:

<?php
  $c = 6;
  do {
    echo 'Hi';
  } while ($c < 5);
  ?>

Even though $c is greater than 5, the script will echo "Hi" to the page.

PHP's do/while loop is not commonly used.

Personal tools