2015-01-21, 11:19 PM
Here is an example of the code I have:
Is there a loop that I could use, to achieve the same functionality, because it would need to loop from 1 until it finds a number.
It will never loop infinite times, because it will always find a number, I just don't know what that number is.
Which loop could I use?
$x = 7; // This number could be any number between 1 and infinity. (It will never be infinity, usually the number will be between 1 & 100).
if ($x === 1) {
$number = 1;
} else if ($x === 2) {
$number = 2;
} else if ($x === 3) {
$number = 3;
} else if ($x === 4) {
$number = 4;
} else if ($x === 5) {
$number = 5;
} else if ($x === 6) {
$number = 6;
} else if ($x === 7) {
$number = 7;
} else if ($x === 8) {
$number = 8;
} else if ($x === 9) {
$number = 9;
} else if ($x === 10) {
$number = 10;
} else if ($x === 11) {
$number = 11;
} else if ($x === 12) {
$number = 12;
//} else if (etc...to infinity, until it finds what $x is equal to)
Is there a loop that I could use, to achieve the same functionality, because it would need to loop from 1 until it finds a number.
It will never loop infinite times, because it will always find a number, I just don't know what that number is.
Which loop could I use?