Part 1
1

Boucles exercices : Example PHP n°4

The questions should help you understand the code shown below.
Once you hold the solution, you can view the answer by clicking on the question title.

Validated example
// affiche les nombres 3 par 3
$i = 20; // variable de boucle
$c = 1; // numero de la colonne
  
  while($i >= 1 )
  {
    print($i.' ');
    if ($c >= 3)
    {  
    print('<br>');
      $c = 0;
    }
    $c++;
    $i--; 
  }
Result :
20 19 18
17 16 15
14 13 12
11 10 9
8 7 6
5 4 3
2 1
20‧19‧18‧<br>17‧16‧15‧<br>14‧13‧12‧<br>11‧10‧9‧<br>8‧7‧6‧<br>5‧4‧3‧<br>2‧1‧

Execution in 0.0004s