Top "Foreach" questions

foreach is a looping construct that executes a given piece of code for each element in a list/collection/array.

Go to "next" iteration in JavaScript forEach loop

How do I go to the next iteration of a JavaScript Array.forEach() loop? For example: var myArr = [1, 2, 3, 4]; myArr.forEach(…

javascript foreach
PHP: Limit foreach() statement?

How can i limit a foreach() statement? Say i only want it to run the first 2 'eaches' or something?

php foreach limit
How to delete object from array inside foreach loop?

I iterate through an array of objects and want to delete one of the objects based on it's 'id' property, …

php foreach unset arrays
Does C have a "foreach" loop construct?

Almost all languages have a foreach loop or something similar. Does C have one? Can you post some example code?

c foreach
How do you remove an array element in a foreach loop?

I want to loop through an array with foreach to check if a value exists. If the value does exist, …

php arrays loops foreach
Return from lambda forEach() in java

I am trying to change some for-each loops to lambda forEach()-methods to discover the possibilities of lambda expressions. The …

java foreach lambda java-8 return-type
Unsetting array values in a foreach loop

I have a foreach loop set up to go through my array, check for a certain link, and if it …

php arrays foreach unset
How to check if variable is array?... or something array-like

I want to use a foreach loop with a variable, but this variable can be many different types, NULL for …

php arrays foreach
Is there a way to avoid null check before the for-each loop iteration starts?

Every time I have to iterate over a collection I end up checking for null, just before the iteration of …

java for-loop foreach
Can one do a for each loop in java in reverse order?

I need to run through a List in reverse order using Java. So where this does it forwards: for(String …

java reverse foreach