Lesson content
Read, practise, then check your understanding
Use for for counting, while for condition-controlled work, do-while when one pass is required, and foreach for arrays and Traversable values.
Practical example
<?php
$scores = ['Mira' => 91, 'Ari' => 76];
foreach ($scores as $name => $score) { echo "$name: $score\n"; }
for ($i = 0; $i < 3; $i++) { if ($i === 1) continue; }
Reference iteration mutates elements but leaves the loop variable referencing the final element; unset it afterward or avoid the pattern. Bound external-data loops, check termination, and consider algorithmic complexity before nesting.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.