‘%s’ operator accepts only positive integers¶
Description¶
The break
and continue
operators only accepts a positive integer as explicit operand.
break
and continue
exit from the current loop. By default, it only exits the current loop; when a higher number is passed, they also exit the next loops.
It makes no sense to exit 0 loops (no need for break
then), or a negative number of loop (call a new foreach
). Break only works with literal integers, and doesn’t compile otherwise.
Example¶
<?php
break 1.2;
continue -1;
?>
Literal Examples¶
‘break’ operator accepts only positive integers
‘continue’ operator accepts only positive integers
Solutions¶
Round the number to the closest integer.
Remove the call to break altogether.
Move the loop in a separate method, and use return to break out of the loop.
Use a goto to jump out of the loop.