Complete the code to print numbers from 1 to 5 using a for loop.
<?php for ($i = 1; $i [1] 5; $i++) { echo $i . " "; } ?>
The for loop runs while the condition is true. Using <= ensures the loop includes 5.
Complete the code to sum numbers from 1 to 10 using a for loop.
<?php $sum = 0; for ($j = 1; $j [1] 10; $j++) { $sum += $j; } echo $sum; ?>
Using <= includes 10 in the sum, so the total is correct.
Fix the error in the for loop condition to count down from 5 to 1.
<?php for ($k = 5; $k [1] 1; $k--) { echo $k . " "; } ?>
Since $k is decreasing, the loop should continue while $k is greater than or equal to 1.
Fill both blanks to create a for loop that prints even numbers from 2 to 10.
<?php for ($m = [1]; $m [2] 10; $m += 2) { echo $m . " "; } ?>
Start at 2 and continue while $m is less than or equal to 10 to print even numbers up to 10.
Fill all three blanks to create a for loop that prints numbers from 10 down to 2, stepping by 2.
<?php for ($n = [1]; $n [2] 2; $n [3] 2) { echo $n . " "; } ?>
Start at 10, continue while $n is greater than or equal to 2, and decrease $n by 2 each time.