Say, for example, I have these parameters set for a for loop:
$b = 5;
for ($a = 0; $a < $b; $a++) {
echo "Looped.";
}
Would there be a way to specifically target one of the looping instances (for this let's just say the 3rd loop) and skip it?
This will do the same as well.
$b = 5;
for ($a = 0; $a < $b; $a++) {
if ($a != 3) {
echo "Looped.";
}
}
You can use continue. For example:
$b = 5;
for ($a = 0; $a < $b; $a++) {
if ($a === 3) {
continue;
}
echo "Looped.";
}
or you could simply use a while loop
$a = 0; $b = 5;
while($a < $b && $a !=3 ){
echo "Looped.";
$a++;
}