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!"
LVL 1
XK8ERAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
nanharbisonConnect With a Mentor Commented:
or if you want to show the number

<?PHP
$checkthisnumber = $_GET['thisnumber'];
 
$i=1;
while ($i < 151) 
{
	
 if ($i == $checkthisnumber) 
 	{
		echo "number found, it is: ". $checkthisnumber;
		break;
	}
$i++;
}
 
?>

Open in new window

0
 
nanharbisonCommented:
this should work

<?PHP
$checkthisnumber = $_GET['thisnumber'];
 
$i=1;
while ($i < 151) 
{
	
 if ($i == $checkthisnumber) 
 	{
		echo "number found";
		break;
	}
$i++;
}
 
?>

Open in new window

0
 
XK8ERAuthor Commented:
yes, the last one is good.. how can I make it show a number not found?
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
XK8ERAuthor Commented:
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
0
 
XK8ERAuthor Commented:
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++;
}

Open in new window

0
 
nanharbisonCommented:
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++;
}
 
?>

Open in new window

0
 
nanharbisonCommented:
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++;
}
 
?>

Open in new window

0
 
nanharbisonCommented:
use the break statement if you want the loop to stop when the number is found.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.