a condition which will not proceed to step unless condition is true
anyone help...:D im creating a personal calendar schedule while Im 开发者_JAVA百科learning PHP. I come across to a part where I need to set a particular condition and then output will only display if condition will be meet. See notes.
$n = 50 $n must not be greater than or equals to 20 [ if ($n >= 20) ] else { $n - 10 }
will only print if $n less than 20
is this possible?? my friends told me to use recursion however i'm not that familiar with it still trying to learn.
Thanks
I believe you are asking about a while-do
- http://php.net/manual/en/control-structures.do.while.php
As per the PHP Manual:
$i = 0;
do {
echo $i;
} while ($i > 0);
Or:
do {
if ($i < 5) {
echo "i is not big enough";
break;
}
$i *= $factor;
if ($i < $minimum_limit) {
break;
}
echo "i is ok";
/* process i */
} while (0);
Is this what you're trying to do?
if ($n <= 20)
{echo $n}
// $n starts at 50
$n = 50;
// so long as n is above or equal to twenty, subtract 10.
while( $n >= 20 ) $n -= 10;
// at this point, n will *always* be less than 20, so we'll out put it.
// print is one way to output n.
print $n;
I think I get what your saying. You want to deduct 10 from the value of $n until you get below 20?
try:
$n = 50;
while($n >= 20){
$n = $n - 10;
}
echo $n;
If $n is less than 20, it will never go into the loop and it will be left alone.
IF $n is greater than 20, it will start deducting 10 and will not preform the echo until $n is less than 20
If you pass in 18, you will echo 18.
If you pass in 50, you will echo 10 (because 20 is still >= 10 so it will deduct once more)
If you pass in 48, you will echo 18
精彩评论