+ 16

why output 1 3 5 7 9 ???

someone can explain???whyyyy for ($i=0;$i<10;$i++){ if($i%2==0){ continue; } echo $i.' '; } //output 1 3 5 7 9

1st Jan 2018, 9:11 PM
Lucifer
Lucifer - avatar
3 ответов
+ 9
Hey, what I believe is happening, is that the continue is causing the remainder of the body of the for loop to be skipped, so instead of printing the number out, it is going straight to incrementing the value of $i. Thus all the even numbers are skipped due to the remainder being 0
1st Jan 2018, 9:21 PM
Tarantino
Tarantino - avatar
+ 1
it simply says if i is equals to zero I is less than 10 so increment I if I modulo 2_ is equal to zero .."only even numbers " continue that means all odd numbers will be the output
6th Jan 2018, 9:33 PM
Android Boi
Android Boi - avatar