Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i skip an output result

Tags:

php

I want to skip the number 10 so that i only have numbers from 15 to 5 without outputting number 10.

    <?php

    $x = 15;
    while($x >=5) {
    echo "$x <br>"; 
    $x--;
    } 

    ?>
like image 303
Jozef Avatar asked Feb 09 '23 19:02

Jozef


2 Answers

<?php
    for($i=15;$i>=5;$i--){
       if($i == 10) continue;
       echo $i . '<br>';
    }
?>

or

<?php
    for($i=15;$i>=5;$i--){
       if($i != 10) echo $i . '<br>';
    }
?>
like image 165
Mihai Zinculescu Avatar answered Feb 12 '23 11:02

Mihai Zinculescu


Add an if condition to ignore $x when it is equal to 10:

<?php

    $x = 15;
    while($x >=5 ) {
        if($x != 10) echo $x . "<br>"; 
        $x--;
    } 

?>`
like image 31
OllyBarca Avatar answered Feb 12 '23 10:02

OllyBarca