Answers for "foreach continue"

PHP
0

foreach skip current iteration

// You can skip the current iteration using "continue"
// Example: Skip the current iteration if $number is 3;
$numbers = [1, 2, 3, 4, 5];

foreach($numbers as $number) {
	if($number == 3) {
    	continue;
    }
	echo $number . " + ";
}
// output: 1 + 2 + 4 + 5 +
Posted by: Guest on January-14-2021
2

continue foreach javascript

elementsCollection.forEach(function(element){
  if (!element.shouldBeProcessed)
    return; // stop processing this iteration

  // This part will be avoided if not neccessary
  doSomeLengthyOperation();
});
Posted by: Guest on October-22-2020
0

php for next loop step

for ($i = 0; $i < 10; ++$i) 
{
  echo "I will loop 10 times";
}
Posted by: Guest on August-06-2020

Browse Popular Code Answers by Language