Top "Foreach" questions

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

Update all objects in a collection using LINQ

Is there a way to do the following using LINQ? foreach (var c in collection) { c.PropertyToSet = value; } To clarify, …

c# .net linq foreach
PHP foreach loop key value

I am running this DB call to get me multi-dimensional array I am trying to get the keys of each …

php foreach
Trying to get property of non-object in

on Control page: <?php include 'pages/db.php'; $results = mysql_query("SELECT * FROM sidemenu WHERE `menu_id`='".$menu."…

php mysql object foreach fetch
LINQ equivalent of foreach for IEnumerable<T>

I'd like to do the equivalent of the following in LINQ, but I can't figure out how: IEnumerable<Item&…

linq foreach ienumerable
Get loop counter/index using for…of syntax in JavaScript

Caution: question still applies to for…of loops.> Don't use for…in to iterate over an Array, use it …

javascript for-loop foreach counter
Is there a 'foreach' function in Python 3?

When I meet the situation I can do it in javascript, I always think if there's an foreach function it …

python python-3.x foreach
Calling remove in foreach loop in Java

In Java, is it legal to call remove on a collection when iterating through the collection using a foreach loop? …

java loops iterator foreach
How do I apply the for-each loop to every character in a String?

So I want to iterate for each character in a string. So I thought: for (char c : "xyz") but I …

java string loops foreach char
break out of if and foreach

I have a foreach loop and an if statement. If a match is found i need to ultimately break out …

php if-statement foreach break
How do I copy items from list to list without foreach?

How do I transfer the items contained in one List to another in C# without using foreach?

c# oop list foreach copy