There is a cycle of 150 steps. It is required to create such a condition under which my code will be executed every 50 steps. The key question is how this condition looks.

 $br = '<br />'; for ($i=0; $i<150; $i++) { echo 'h'; if (требуемое условие) echo $br; } 

    3 answers 3

     $i % 50 == 0 

    The remainder of division by 50 is 0. That is, the number is a multiple of 50.

    • one
      $i % 50 == 0 so the author will display after the 51st entry h - mix
    • In this case, you need to use $i % 50 == 1 or start counting from one. The essence does not change. - Razzwan
    • also incorrectly displays. The account must begin with a unit. - mix
     $br = '<br />'; for ($i=1; $i<=150; $i++) { // $i = 1 чтобы счет начинался с 1, а не с 0 echo 'h'; if ($i % 50 == 0 ) echo $br; } 
    • Thank you kind people! - array05
     if ( ($i>0) && (($i % 50) == 0) ) 
    • In the question from 0 to 149 ( $i<150 ), therefore, probably, it is necessary to fulfill with 0. - Sergiks