by Hiroshi on June 21st, 2008
The while keyword takes a condition in parentheses, and the code block that follows is repeated while that condition is true. If the condition is false initially, the code block will not be repeated at all.
The repeating code must perform some action that affects the condition in such a way that the loop condition will eventually no longer be met; otherwise, the loop will repeat forever. Such loops are Infinite Loops.
Structure Of PHP While Loop
- Define
- Condition
- Print
- Increment or decrement
while ( conditional statement is true)
{
//do the task;
}PHP While Loop Example
<?php $num = 3; while($num < 10) { echo $num; $num = $num + 1; $num++; } // Output: 3579 ?>
<?php $count = 1; while ($count <= 10) { $square = $count * $count; echo "$count squared is $square <br />"; $count++; } // Output: // 1 squared is 1 // 2 squared is 4 // 3 squared is 9 // 4 squared is 16 // 5 squared is 25 // 6 squared is 36 // 7 squared is 49 // 8 squared is 64 // 9 squared is 81 // 10 squared is 100 ?>
One Review
Leave a Review
Incoming Searches
how can i repeat the images in php by for loop/, 3 squared is 9 php, php while loop in image gallary, php while loop image, php while loop count, php while loop, php while counter, php loop image, php loop for counting 1 to 5, php while loop square, php while loop wp, Php-while loop, scope of while loop php, while loop count in php, while loop counting number in php, while loop counting php, while loop in wp, while loop repeat in mysql with php, php for while, php for loop count(), ajax with php while loop, count values in php while loop, count(*) php, counter loop php, do while loop php example code, feeds met php script, for loop php count, how to create form for reply in while loop in php, image gallery php tutorial while loop, image-galleries-loop php free, loop and count the phone number php, loop atoz in php, loop count in php, loop to square 2 numbers in php, looping counter code of php, mysql php while loop counter, while loop square



[...] “do while†loop is a slightly modified version of the while loop. A do-while loop first do’s and secondly checks the while [...]