Garetty Posted September 23, 2009 Share Posted September 23, 2009 I have this section of my script (I have changes the variables and other stuff around): fwrite(STDOUT, "\nWould you like to choose your favorite number? (Yes/No):\n"); $Answer = trim(fgets(STDIN)); if ($Answer == "Yes") { fwrite(STDOUT, "\nWhat number do you like?(1-50000)\n"); $Number = trim(fgets(STDIN)); echo"\nAttempting to do this.\n\n"; if ($Number >= 0 && $Number <= 25000) { $Loops = 1; while ($Loops <= 1) { /////////////////////// // Do My Stuff // /////////////////////// echo $Number++; } } elseif ($Number >= 25001 && $Number <= 50000) { $Loops = 2; while ($Loops <= 1) { /////////////////////// // Do My Stuff // /////////////////////// echo $Number++; } } else { echo"\n\n\n\n\n\n\nAn Error Occurred while getting the number. Try again.\n\n\n\n\n\n\n\n\n"; while(true){} } } I can get this to work if I enter a number lower than 25000, but if I enter 25000 to 50000 it will not do the stuff. How can I make it so that it will work correctly? Quote Link to comment https://forums.phpfreaks.com/topic/175285-if-statement-help/ Share on other sites More sharing options...
Garethp Posted September 23, 2009 Share Posted September 23, 2009 Look here $Loops = 2; while ($Loops <= 1) { It's not running the loop at all. Change that $Loop to =1; Next time, can you be more specific in your post? Quote Link to comment https://forums.phpfreaks.com/topic/175285-if-statement-help/#findComment-923829 Share on other sites More sharing options...
Psycho Posted September 23, 2009 Share Posted September 23, 2009 While Garethp is correct that that loop will never run, I would not suggest using his "fix" unless you want an infinite loop. You must use two equal signs to see if two values are equal. using a single equal sign will only assign the value to the variable. However, it looks like you are using the $Loops variable as a switch with 1 indicating that the loop should continue and any other value that it shoudl exit. unless you have some other use for the value assigned to that variable, you should just use true/false instead. Quote Link to comment https://forums.phpfreaks.com/topic/175285-if-statement-help/#findComment-923834 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.