Top "Foreach" questions

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

How does PHP 'foreach' actually work?

Let me prefix this by saying that I know what foreach is, does and how to use it. This question …

php loops foreach iteration php-internals
Linq style "For Each"

Is there any Linq style syntax for "For each" operations? For instance, add values based on one collection to another, …

c# .net linq foreach
Is there a foreach loop in Go?

Is there a foreach construct in the Go language? Can I iterate over a slice or array using a for?

go foreach slice
How to store values from foreach loop into an array?

Need to store values from foreach loop into an array, need help doing that. The code below does not work, …

php foreach
Find the last element of an array while using a foreach loop in PHP

I am writing a SQL query creator using some parameters. In Java, it's very easy to detect the last element …

php foreach
change values in array when doing foreach

example: var arr = ["one","two","three"]; arr.forEach(function(part){ part = "four"; return "four"; }) alert(arr); The array is still …

javascript arrays foreach pass-by-reference
How to avoid java.util.ConcurrentModificationException when iterating through and removing elements from an ArrayList

I have an ArrayList that I want to iterate over. While iterating over it I have to remove elements at …

java arraylist foreach
Javascript foreach loop on associative array object

Why my for for-each loop is not iterating over my JavaScript associative array object? // defining an array var array = []; // assigning …

javascript arrays foreach
Python foreach equivalent

I am diving into Python and I have a question about foreach iteration. I am new to Python and I …

python foreach
Bash foreach loop

I have an input (let's say a file). On each line there is a file name. How can I read …

bash foreach