foreach Questions

10

Solved

When the enhanced for loop (foreach loop) was added to Java, it was made to work with a target of either an array or Iterable. for ( T item : /*T[] or Iterable<? extends T>*/ ) { //use item...
Alcestis asked 7/10, 2010 at 15:15

11

Solved

Why are assignment operators (=) invalid in a foreach loop? I'm using C#, but I would assume that the argument is the same for other languages that support foreach (e.g. PHP). For example, if I do ...
Nape asked 23/8, 2010 at 16:47

12

Solved

I have a foreach loop and I want to see if there is a next element in the loop so I can compare the current element with the next. How can I do this? I've read about the current and next functions ...
Malacology asked 23/2, 2011 at 20:38

3

Solved

It's fairly well documented that foreach processing speed varies depending on the way a foreach loop is carried out (ordered from fastest to slowest): .ForEach() method foreach ($item in $collecti...
Votive asked 15/12, 2023 at 4:50

26

Solved

I want to generate a selectbox using two arrays, one containing the country codes and another containing the country names. This is an example: $codes = ['tn', 'us', 'fr']; $names = ['Tunisia', 'Un...
Flotsam asked 18/12, 2010 at 23:41

3

I have a bit of dilemma, In PHP both foreach loop and while loop seem to do exactly the same thing in this situation: foreach ($execute->result as $item) { echo $item['user_pass'] . '<br /&g...
Metempirics asked 10/10, 2014 at 13:44

6

Solved

I am running a forEach loop on an array and making two calls which return promises, and I want to populate an object say this.options, and then do other stuff with it. Right now I am running into t...
Nomen asked 13/7, 2016 at 21:45

11

Solved

Here are the inputs I want to loop through Main photo: <input type="file" name="image[]" /> Side photo 1: <input type="file" name="image[]" /> Side photo 2: <input type="file" name...
Divertissement asked 26/3, 2011 at 19:41

3

Solved

I have a List<LedgerEntry> ledgerEntries and I need to calculate the sums of creditAmount and debitAmount. class LedgerEntry{ private BigDecimal creditAmount; private BigDecimal debitAmoun...
Patricio asked 22/2, 2017 at 8:25

4

Solved

Let's say we have an array of objects like: var fruits = [ {name:"banana", weight:150},{name:"apple", weight:95},{name:"orange", weight:160},{name:"kiwi", weight:80} ]; I want to populate a "hea...
Footton asked 9/8, 2016 at 15:52

6

Solved

Sometimes I use same foreach operation with different target files in csh. If I can give foreach command in a single line, I could easily substitue the target file names to repeat the process.(I us...
Careerist asked 12/9, 2014 at 12:27

9

Solved

I am making my own implementation of forEach in javascript, with the sole purpose of understanding the language better. To be more specific the temporary goal is to understand callbacks better. T...
Mangosteen asked 25/9, 2018 at 15:26

2

Solved

I have a list of objects Human. I need to get a list of its id. I do that. Can i do it more simplier? It looks not so good val idsList = ArrayList<Int>() humansList.forEach{idsList.add(it.id...
Robby asked 8/6, 2021 at 6:57

8

My problem is that i have (in SwiftUI) a ScrollView with an foreach inside. Know when the foreach loads all of my entries i want that the last entry is focused. I did some google research, but i d...
Drool asked 14/10, 2019 at 12:20

7

I am trying to execute parallel functions on a list of objects using the new C# 4.0 Parallel.ForEach function. This is a very long maintenance process. I would like to make it execute in the order ...
Erection asked 3/9, 2010 at 21:46

3

Solved

I've looked through much of the documentation and done a fair amount of Googling, but can't find an answer to the following question: Is there a way to induce 'next-like' functionality in a paralle...
Hendren asked 10/10, 2011 at 0:12

3

Solved

I am parsing html in the $content variable with the DOMDocument to replace all iframes with images. The foreach is only replacing the ODD iframes. I have removed all the code in the foreach and fou...
Va asked 23/1, 2015 at 22:32

3

Solved

<?php $a = array('a', 'b', 'c', 'd'); foreach ($a as &$v) { } foreach ($a as $v) { } print_r($a); ?> I think it's a normal program but this is the output I am getting: Array ( [...
Magistracy asked 11/2, 2011 at 12:58

9

Solved

Is there an easy way to slow down the iteration in a forEach (with plain javascript)? For example: var items = document.querySelector('.item'); items.forEach(function(el) { // do stuff with el a...
Chavis asked 4/8, 2017 at 5:30

9

Solved

I need to deploy a list of GCP compute instances. How do I loop for_each through the "vms" in a list of objects like this: "gcp_zone": "us-central1-a", "image_n...
Watercool asked 28/10, 2019 at 16:12

3

Solved

lets say I have 10 submoules: module/1 module/2 module/3 module/4 module/5 module/6 module/7 module/8 module/9 module/10 where module/ is the top-level repo. I want to do git submodule foreach ...
Ameliorate asked 8/10, 2019 at 17:30

6

Solved

I'm struggling to understand the difference between forEach and map. In the following render function if the 'forEach' is replaced with 'map' it works. I don't understand why it doesn't work with t...
Cranky asked 22/11, 2017 at 19:26

8

Solved

I'm using a foreach loop to go through the REQUEST array, as I want to have an easy way to utilize the REQUEST array's keys and values. However, I also want to have a numerical index of how many t...
Harneen asked 13/8, 2012 at 14:36

5

Solved

How it is posible to fix this script? Yes, I´m changing the collection in the foreach loop and this is the reason for this error. An error occurred while enumerating through a collection: Collect...
Siegfried asked 25/1, 2012 at 15:31

23

Solved

Are there any advantages of std::for_each over for loop? To me, std::for_each only seems to hinder the readability of code. Why do then some coding standards recommend its use?
Longitude asked 12/1, 2010 at 7:37

© 2022 - 2024 — McMap. All rights reserved.