Back to questions
JuniorTheoryCommon
What does the program print?
<?php
for ($i = 1; $i <= 10; $i++) {
if ($i % 2 === 0) {
continue;
}
if ($i > 6) {
break;
}
echo $i;
}
echo "\n";135
- Expecting
breakto leave only theifit sits in:breakends the nearest loop, so after7no more numbers are checked. - Expecting
continueto stop the loop: it skips the rest of the current pass, then$i++runs and the condition is checked again.
- What does the program print if
continueandbreakswap places? - What value does
$ihold after the loop ends?