Simple if condition makes for loop infinite?

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
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Simple if condition makes for loop infinite?

Post by JAB Creations »

The following for loop works just fine until I uncomment the if conditions, can someone kindly explain why please?

Code: Select all

for ($i = 1; $i <= $pages; $i++)
 {
  echo '<option ';
  //if ($i = $_GET['p']) {echo 'selected="selected" ';}
  echo 'value="'.$i.'">';
  //if ($i = $_GET['p']) {echo 'You are currently viewing ';}
  echo 'Page '.$i.'</option>'."\n";
 }
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Simple if condition makes for loop infinite?

Post by alex.barylski »

See point #5 in my blog entry. :P

Your using a assignment instead of comparison in both IF's that might have something to do with it. ;)
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Simple if condition makes for loop infinite?

Post by JAB Creations »

DOH!

Thanks for pointing out the obvious...

"No question is so difficult to answer as that to which the answer is obvious." - George Bernard Shaw
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Simple if condition makes for loop infinite?

Post by alex.barylski »

Haha...it happens...your eyes get tired and you miss stupid little things like that...

p.s-Your situation doesn't apply to my blog either, so nevermind about that. :P
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Simple if condition makes for loop infinite?

Post by JAB Creations »

I'm not tired right now...I have an odd sleeping pattern at the moment. :mrgreen:

I'm reading your blog right now, thanks for mentioning it.
Post Reply