Page 1 of 1

Why this code forms infinite loop ...

Posted: Mon Apr 28, 2008 9:52 am
by sjohnranjan
Please tell me why this code forms infinite loop

<?php

$temp = 1;
while($temp<=10)
{
echo "The no is : " . $temp . "<br>";
$temp = $temp++;
}


?>

Re: Why this code forms infinite loop ...

Posted: Mon Apr 28, 2008 10:23 am
by s.dot
$temp++ returns $temp and THEN increments it

try $temp = ++$temp;

or simply..

$temp++;

Re: Why this code forms infinite loop ...

Posted: Mon Apr 28, 2008 11:56 am
by Zoxive