While Loops in PHP
Completing the Loop

In the previous exercise, you saw how a do/while could be used to ensure that the code in a loop executed at least once. For example:

$i = 0;
do {
    echo $i;
} while ($i > 0);

This do / while loop only runs once and then exits:

  1. First we set $i equal to 0.
  2. Second, the loop runs once and outputs $i, which is 0.
  3. Then the condition while ($i > 0); is checked. Since $i is not greater than 0, the condition evaluates to false, and thedo/while` loop stops.

Starting on line 9, there is a do / while loop that should run only once and then exit. But it's missing curly braces { }, parentheses ( ), and semicolons ;.

  1. Fill in the missing { }, ( ) and ; to make sure the do/while loop runs correctly. Check out the do / while loop above for an example.
  2. Then click "Save & Submit Code" and verify that the page looks the way you expected.
Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

You will need to fill in the following characters: {, }, (, ), ;, and ;, but not necessarily in that order.

View Preview