Skip to main content

Questions tagged [foreach]

foreach is a looping construct that executes a given piece of code for each element in a list/collection/array. In contrast to a for loop, the foreach loop doesn't require the coder to maintain a counter variable to avoid off-by-one (fencepost) bugs. It is recommended to use when simple iteration over whole array/list/collection is needed.

Filter by
Sorted by
Tagged with
0 votes
1 answer
27 views

Have my array be split and added on to the new array, instead of completely restarting it each loop

I have a problem with my array. Each loop, the array gets cleared and new values gets added onto it. How could I make it so as the array gets filtered, it gets added to a new array to fill it up with ...
Legois's user avatar
  • 1
3 votes
2 answers
98 views

What is the difference between returning Select() and yield return?

Examples: public IEnumerable<Class> ReturnClass() { var list = ...; return list.Select(item => { // if, else, etc return item; }); } or public IEnumerable&...
Luiz's user avatar
  • 159
-2 votes
0 answers
42 views

Better way of mapping nested arrays in javascript? [closed]

I have an object const resp = [ { "projectId":"26549b0e-bf31-db41-f2c0-734be4220846", "projectName":"Project 1", "jobs":[ { ...
dariusz's user avatar
  • 513
0 votes
2 answers
69 views

Multiple looping with config file in bash

I want to copy latest file based on filename in (filename_config) & in each directory based on config file (dir_config) to backup directory. In one directory could have > 1 filename to be copy. ...
Miss aya's user avatar
0 votes
1 answer
46 views

Understanding Error CS1579 foreach statement cannot operate on variables of type

Getting this error in my razor page app: Severity Code Description Project File Line Suppression State Error (active) CS1579 foreach statement cannot operate on variables of type '...
MelB's user avatar
  • 173
-1 votes
0 answers
16 views

I need a function to Get the Length of the SenderDomains under some InboundConnectors in Exchange Online

I found this function to get the Lenght of 1 InboundConnector for the field "SenderDomains" in ExO: Get-cloudInboundConnector -Identity "Inbound Required TLS 2" | select -...
Juanjo Megías's user avatar
0 votes
1 answer
56 views

Azure Data Factory ForEach inner activity error message

In ADF, how do you get the actual error message of the failed activity inside the ForEach, instead of the msg "Activity failed because an inner activity failed". I want to get the actual ...
James's user avatar
  • 1
-1 votes
1 answer
33 views

Create proper resource names using terraform for_each

I would like to create several service account using for_each loop with the names: yandex_iam_service_account.loki["loki1"] yandex_iam_service_account.loki["loki2"] etc... It is ...
poisoned_monkey's user avatar
-1 votes
1 answer
38 views

%dofuture% foreach file not found warning

Trying to get %dofuture% to work, but getting an error using the following code. Not sure why. library(foreach) library(doParallel) library(doFuture) plan(multisession,workers=availableCores()) # ...
Maize Blue's user avatar
1 vote
1 answer
43 views

Append information to the output of an existing command

A former colleague gave me these two PowerShell scripts to run, log, and monitor a continuous ping test: Run & Log: ping.exe -l 1500 -t W2K16svr|Foreach{"{0} - {1}" -f (Get-Date),$_} | ...
Ants1060's user avatar
  • 186
0 votes
0 answers
10 views

jsp <c:forEach table not generating [duplicate]

This is how I populate table public List<String[]> listTable = new ArrayList(); String[] foundPost = {"name", "nickName", "datePost", "subject", "...
Geoffrey Hebert's user avatar
-3 votes
1 answer
55 views

Foreach can't be used for variables of type "PropertyInfo" because "PropertyInfo" has no defintion for "GetEnumerator"

I want to iterate throug a Dictionary<string, object> with a foreach loop. First I get all of the items with reflection. And when item.Name is not settings the program goes in the else path. ...
user1673665's user avatar
3 votes
1 answer
68 views

Remove In Nested Loops (Remove Inside Foreach) [closed]

These are my entities: public class Permissions { public string PermissionName { get; set; } public List<Controllers> controllers { get; set; } } public class Controllers { public ...
Yasim Yasin's user avatar
0 votes
0 answers
23 views

How can I output a list of objects in a CloudFormation template?

I've got a template for an ECS service which I am using for multiple different microservices. I need to start passing different secrets to some of the services. I'm trying to pass in a comma separated ...
Andrew Williamson's user avatar
-1 votes
2 answers
117 views

C# - Foreach won't let me use string for string [closed]

Apart from the fact that I'm still a beginner in this language, I don't understand foreach very well. public static void test () { string str = ""; foreach (string line in str) {...
Pedro Gabriel's user avatar
0 votes
1 answer
64 views

KDB/q: forEach loop to execute a block of code with a specific parameter

I am trying to make a loop which parses the list and uses each list item inside the loop in the code block but in q lang I want it to be something like this- countryList: //list of all countries for ...
Sakshi Pandey's user avatar
0 votes
1 answer
67 views

@foreach Isn't Doing Everything for each record

I have a razor page that is looking at a list of people and their votes. It is bringing up items like Municipality, Supervisor, Simple Majority, 2/3 Majority just fine, but when it comes to ...
MelB's user avatar
  • 173
0 votes
2 answers
45 views

Why do these for-each and value-of tags in XSLT not select the values properly? [closed]

For class we're supposed to write an XSLT file that takes in our XML file, filters out parts of it and then displays some data from what's left in a new XML file. In my case there's a wrapper "...
FatSouls's user avatar
0 votes
0 answers
65 views

Laravel Foreach in Foreach Loop (Loop Design)

I am making a registration system with reference. Everything works fine so far, but there's a point I'm stuck on. First of all, anyone who is a member can invite someone. The person who accepts the ...
muratapps's user avatar
0 votes
0 answers
47 views

SwiftUI Using dynamic nested dictionary values as Binding Values - issues with wrapping

The gist of the issue is that I want to filter a list of items based on various criteria from the list itself. For example, I have a list of food items, and I want to filter based on the possible ...
learnandgrow's user avatar
0 votes
1 answer
41 views

Get-EventLog loop for psobjects, strange results

I've to collect certain events for sharing it by mail; I'm missing something because the script, take a lot of time for only 2 servers and, the result is absurd! Server1 events count: $Etype = @( &...
ilRobby's user avatar
  • 81
0 votes
1 answer
41 views

R: passing foreach loop number (i) to an object and then passing that object to a function

In R, I'm attempting to run the following foreach loop in parallel using the doFuture package For some reason the loop number (i) is not being passed to set the object "Current_File" (I ...
Maize Blue's user avatar
-1 votes
0 answers
22 views

Return statement in the forEach callback function

for this code not to run the console.log(element) after the return statement, does it means that it is because, when we use the return keyword, any other code that comes after doesn't run? When I ran ...
Onah Victor's user avatar
0 votes
1 answer
62 views

Problem with a query when comparing dates in Laravel based project

I'm working on apartments rental project. As a part of the applications abilities there is a functionality for an apartments owner to select days that the apartment is available for rental by guests. ...
Makhmud's user avatar
0 votes
0 answers
16 views

Creating a single paragraph with loop Velocity

I have multiple variables in a list and I want to create a single paragraph for all of them that share the same property of what we'll call class.requirement for example's sake. I want to make a ...
Julia Sullivan's user avatar
0 votes
1 answer
25 views

How to use foreach in Ajax GET method?

I have a problem. For a calendar, I would like to display appointments that belong to the logged-in user with details, while all other appointments in the database should be grayed out. The is the ...
Sven's user avatar
  • 1
0 votes
1 answer
43 views

remove multiples rows from datatable based on their respective indexes in jquery

I want to remove some rows from datatable based on their respective indexes.The indexes are in form of an array. Upon clicking a button the function gets the array and finds each of them in the ...
Steve Djvoskill Waweru's user avatar
-3 votes
1 answer
104 views

If an element exist in a list, ignore other similar elements in c# [closed]

I have got a string list with generated programmatically like this: var list = new List<string> { "anonim", "anonim şirket", "anonim şirketler", &...
Johnny Wind's user avatar
-3 votes
2 answers
61 views

Can someone please explain the behavious of the console.log() within the for loop below [closed]

I came across the forEach() method in one of my exercise work and I decided to read more about it. During my research, I came across an example of a for loop being converted to forEach() method. I ...
emjKamara's user avatar
0 votes
0 answers
44 views

CREATING a table like using a For Each loop

I have 3 tables that I need to relate to a fourth table. I'm trying to put everything in a temporary table first for review. The final table has 5 columns, [ID], [Name], [Email], [LocationID], [...
Sam Ryan's user avatar
0 votes
0 answers
24 views

Error in {task 1 failed - [readValues] cannot read values in R doParallel "foreach"

I am trying to speed up an intervisibility calculation between landscape viewpoints (X, Y, height), using a rasterprofile and line of sight functions over a digital elevation model. I ran a large-...
Adela's user avatar
  • 36
0 votes
0 answers
39 views

SwiftUI - nested ForEach causes compiler confusion

I'm drawing connected shapes, where a shape can connect to one or more downstream shapes. The data model is straightforward: @Observable class GadgetModel: Encodable, Identifiable { var gadgets = ...
Andromeda's user avatar
  • 673
1 vote
2 answers
67 views

Using both foreach and bam from the mgcv package

I have several large GAM models to fit (lots of data, various distributions for residuals and random effect smooths). Currently, I use foreach with a cluster of processors based on the parallel ...
David M. Kaplan's user avatar
0 votes
1 answer
40 views

ADF - How to set item from for each loop into copy data

I have below url set as baseurl in http linked service: https://app.zipcodebase.com/api/v1/country/province?apikey=997db720-a95e-dd921aaa6fad&country= I have created below datasets and set ...
microset's user avatar
  • 358
0 votes
0 answers
25 views

Populate fields on 365 mailboxes through ExchangeOnline PS script

getting a "Cannot bind argument to parameter 'Identity' because it is null" in this script : # Import Exchange Online PowerShell Module Import-Module ExchangeOnlineManagement # Connect to ...
arty0m's user avatar
  • 1
0 votes
2 answers
29 views

Filter sets by a boolean column

I have a list of customers and there are many duplicates. To solve this problem the business is setting one of them as primary. The process has not been followed; I need to find all the customers that ...
John McEvoy's user avatar
1 vote
1 answer
48 views

Why can Rename-Item be piped directly to Get-ChildItem? [duplicate]

To use Powershell to execute a program against all files in a directory, the command should be: Get-ChildItem -File | Foreach {myprog $_.fullname} However, I can use Rename-Item directly without ...
Ooker's user avatar
  • 2,601
0 votes
0 answers
13 views

Adding a template to multiple existing sharepoint sites

I have made a code for adding a template to multiple existing SharePoint sites at once with foreach and Import-csv. I think it almost works but I keep getting the same error. PS C:\WINDOWS\System32>...
Logan's user avatar
  • 11
0 votes
0 answers
27 views

Using Import csv and foreach to duplicate template to multiple sharepoint sites

I have a question about SharePoint online. Our project assignment is to make new sites for our client. We want to design a script that makes it easier to use a template and add that to a site. I have ...
Logan's user avatar
  • 11
1 vote
1 answer
47 views

Loop through sheets to remove textboxes and change font color

I am looking for code that will circle through all worksheets and set the font of all cells to black. Moreover it should remove all textboxes inside and I would be pleased if it could replace them by ...
user25276741's user avatar
0 votes
0 answers
8 views

Divs eventlistner and Toggle

Please I am having issues with my code, I have 4 div which are flexed and I also have a read more button in each of the div and a P in each div that do not display until the button is clicked my ...
Jennifer Okoroji's user avatar
0 votes
0 answers
46 views

VB.net Nested 'For Each' Loop Slow

Can someone suggest how I can improve the performance of my nested For Each loops? This logic accepts a string variable CSV style parameter and converts it into a data table. We are adding some ...
Candace Aisenbrey's user avatar
0 votes
1 answer
39 views

Foreach 'file' copy-item only copies the last results 'file' to destination but copies to all folders instead of its respective folder

I am no expert in PowerShell and apologies if my script is way off but I really could use some help on this. I appreciate any help!! I need to copy ONLY '.bak' files from a Server with folder ...
sllucas's user avatar
0 votes
0 answers
25 views

How to build If condition comparing metadata output against a variable containing multiple values

sorry newbie here. I have a variable ('small_list') with default value [ 'A', 'B', 'D']. I have a Get Metadata that will get foldernames from a container (A,B,C,D,E,F). Using a ForEach to loop round ...
user22538275's user avatar
0 votes
1 answer
62 views

Facing issue in list radio button selection in swiftui

code: with this code i am able to select each question multi check boxes but when it comes selecting radio button selection then i can able to select any one question options... if i select another ...
Swift's user avatar
  • 1,170
1 vote
1 answer
51 views

Netlogo: efficient iteration using 'foreach'

I want to calculate and store two certain quantities associated with turtles' properties, namely count how many turtles meet a condition and the sum of these turtles' specific attribute. That specific ...
G. Papad.'s user avatar
0 votes
1 answer
39 views

Flutter Dart - Foreach behaviour not clear here

Flutter version: 1.89+ I have a custom function as below: Future<List<CustomListItems>> getPrevChats() async { List<CustomListItems> vList = []; final Stream<...
Art Media's user avatar
2 votes
2 answers
40 views

I see the filtered data on the screen, but the original data does not appear when I clear the input

I see the filtered data on the screen, but the original data does not appear when I clear the input Here I show _todayShare in the <a\> tag as an item in order <span>Share</span> ...
Serkan's user avatar
  • 31
2 votes
4 answers
78 views

C++ : A bug in a foreach loop in a function with array input

I'm a beginner and as an exercise I tried to create a function which gets an array of integers as input and returns their maximum. Here's the code: #include <iostream> int maximum(int ...
The Bluehame Owl's user avatar
-1 votes
3 answers
54 views

php while loop inside foreach only executes on first loop

I have an array of values and I use a while loop to lookup a CSV file for each of those values and make a list of any matches But, for some reason the while loop only executes for the first foreach ...
Brick's user avatar
  • 99

1
2 3 4 5
516