Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/175285-if-statement-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/175285-if-statement-help/#findComment-923834
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.