11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 3 • <strong>PHP</strong> BASICSwww.it-ebooks.infoThe do...while StatementThe do...while looping statement is a variant of while but it verifies the loop conditional at theconclusion of the block rather than at the beginning. The following is its syntax:do {statements} while (expression);Both while and do...while are similar in function. The only real difference is that the codeembedded within a while statement possibly could never be executed, whereas the code embeddedwithin a do...while statement will always execute at least once. Consider the following example:The following is the outcome:11 squared = 121Despite the fact that 11 is out of bounds of the while conditional, the embedded code will executeonce because the conditional is not evaluated until the conclusion.The for StatementThe for statement offers a somewhat more complex looping mechanism than does while. The followingis its syntax:for (expression1; expression2; expression3) {statements}There are a few rules to keep in mind when using <strong>PHP</strong>’s for loops:• The first expression, expression1, is evaluated by default at the first iteration of theloop.• The second expression, expression2, is evaluated at the beginning of eachiteration. This expression determines whether looping will continue.• The third expression, expression3, is evaluated at the conclusion of each loop.• Any of the expressions can be empty, their purpose substituted by logic embeddedwithin the for block.82

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!