XK8ER
asked on
number checker
hello there,
I would like to create something so that if I give a number lets say (150)
the code checks from 0 until 150 and once it finds it then say "number found!"
I would like to create something so that if I give a number lets say (150)
the code checks from 0 until 150 and once it finds it then say "number found!"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes, the last one is good.. how can I make it show a number not found?
ASKER
lets say I type number 6 it should be like
1 not found
2 not found
3 not found
4 not found
5 not found
6 number found
1 not found
2 not found
3 not found
4 not found
5 not found
6 number found
ASKER
ok I think I got it!
$checkthisnumber = '50';
$i=1;
while ($i < 151)
{
if ($i == $checkthisnumber)
{
echo $checkthisnumber . ' number found';
break;
}
else
echo $i . ' not found<br>';
$i++;
}
like this
<?PHP
$checkthisnumber = $_GET['thisnumber'];
$i=1;
while ($i < 151)
{
if ($i == $checkthisnumber)
{
echo "number found, it is: ". $checkthisnumber;
} else {
echo $checkthisnumber." was not found ";
}
$i++;
}
?>
oops, that was wrong
<?PHP
$checkthisnumber = $_GET['thisnumber'];
$checkthisnumber = 100;
$i=1;
while ($i < 151)
{
if ($i == $checkthisnumber)
{
echo "number found, it is: ". $checkthisnumber;
} else {
echo $i." was not found<br /> ";
}
$i++;
}
?>
use the break statement if you want the loop to stop when the number is found.
Open in new window