I am primarily a CSS and HTML guy but I have recently ventured into PHP.
I can't see why this script hangs:
$loop_Until = 10;
while($i < $loop_Until)
{
// do some code here
$loop_Until = $loop_Until + 1;
}
Can anyone please help?
We can print numbers from 1 to 10 by using for loop. You can easily extend this program to print any numbers from starting from any value and ending on any value. The echo command will print the value of $i to the screen. In the next line we have used the same echo command to print one html line break.
In PHP, we have the following loop types: while - loops through a block of code as long as the specified condition is true. do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true. for - loops through a block of code a specified number of times.
php $end=50; $even= "Even Numbers Are : "; $odd="<br /> Odd Numbers Are : "; for($i=1;$i<=$end;$i++) { if($i%2==0) { $even. =$i.","; }else $odd.
Fixed Code
$loop_Until = 10;
$i = 0;
while($i < $loop_Until)
{
// do some code here
$i = $i + 1;
}
Explanation of your code:
// A variable called loop until is set to 10
$loop_Until = 10;
// While the variable i is less than 10
// NOTE: i is not set in code snippet, so we have no way of knowing what value it is, if it is greater than 10 it might be infinite
while($i < $loop_Until)
{
// Increment the 10 value up 1 every time, i never changes!
$loop_Until = $loop_Until + 1;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With