From the course: Learning PHP

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Do/while loops

Do/while loops - PHP Tutorial

From the course: Learning PHP

Start my 1-month free trial

Do/while loops

- [Instructor] The most common form of loop is a do while loop. These will continue to run until some condition becomes false. They are general purpose loops that can be used for anything. And there are actually two types of syntax for these loops. The first uses the keyword "do." So we'll add our php tags. Let's create some condition here. We'll say i is zero, and then we'll start our loop. So this could say, do echo, i, while i is less than 10. So this loop will execute and print out the value of i, as long as i is less than 10. So we should see the numbers zero through nine, printed out on the page. But we don't. And you could see that our program is still running here. That's because we forgot one crucial part of the loop, which is the incrementor. So if we add, i++ save and refresh. Now, we have a list of numbers from zero through nine, and then our loop terminates. Do while loops are great if you want…

Contents