PHP 5 while Loops

<?php $x = 1; while($x <= 5) { echo "The number is: $x <br>"; $x++; } ?> <?php $x = 1; do { echo "The number is: $x <br>"; $x++; } while ($x <= 5); ?>

1 Response

Use ++$x; whenever possible, it's tremendously faster, as are foreach loops over while loops. It prevents an erroneous conditional evaluation.

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.