Tsallaka zuwa abun ciki
Justice Tech School

for and while Loops

for has init, condition and step. while repeats while true. do while runs at least once.

Example
for ($i = 1; $i <= 3; $i++) echo $i, " ";
$n = 3;
while ($n > 0) { echo $n--, " "; }
do { echo "once"; } while (false);

Result

1 2 3 3 2 1 once

Exercise

Loop keyword.

 ($i = 0; $i < 3; $i++) {}

Quiz Test

Which runs at least once?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.