Why this code forms infinite loop ...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sjohnranjan
Forum Newbie
Posts: 1
Joined: Tue Jan 15, 2008 10:27 pm

Why this code forms infinite loop ...

Post 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++;
}


?>
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Why this code forms infinite loop ...

Post by s.dot »

$temp++ returns $temp and THEN increments it

try $temp = ++$temp;

or simply..

$temp++;
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Why this code forms infinite loop ...

Post by Zoxive »

Post Reply