As of May 31, 2023, we have updated our Code of Conduct.

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
0 answers
22 views

Makefile - foreach directory, check condition then run piped bash commands

Hello people of the internet, Firstly I must apologize as I am relatively new to makefiles so I may be doing this in a very unorthodox way. I am trying to create a makefile that will -loop through ...
Koa's user avatar
  • 1
0 votes
2 answers
59 views

Why does Java for-each loop execute methods on all objects in array?

I'm a beginner to coding and trying to implement a Java for-each loop for a simple project. The project in question has the classes LibraryMember and Book, and the class Library contains the other two ...
AzureBoredom's user avatar
0 votes
2 answers
36 views

Using str_starts_with to check if a number starts with a given phone code (using array and foreach) [duplicate]

I'm currently struggling with a PHP issue : I'd like to use the str_starts_with function (AFAIK available from PHP 8.0) to check if a given phone number actually starts with a phone code (all the ...
eyescrime13's user avatar
0 votes
0 answers
14 views

FOR EACH LOOP Container working in SSIS but failing as an SQL Job or in SSISDB Integration Service Catalogs, Even after providing correct File path

I am transferring data from folder(contains CSV Files) to SQL Server database using FOR EACH LOOP Container in SSIS. That works well in SSIS but it is giving me an error while running as SQL Jobs or ...
Ishani's user avatar
  • 1
0 votes
1 answer
56 views

Adding header to last column once & checkboxes to certain rows at last column

I am having an issue with the above. I have an input table/form where a user will be making various selections via drop-downs in certain cells and inputting values in others. For this code, I am ...
StillLearningThisStuff's user avatar
0 votes
0 answers
25 views

Improve web scraping speed using parallel processing in R

I have a R script which queries a HS Code in a website and fetches the required data and I export this data into an excel book. But the problem is, for each HS Code, the navigation in the website is ...
Frodo's user avatar
  • 260
0 votes
1 answer
19 views

How can I return Wordpress content with generated ID's based on the number of H2 tags

What I'm trying to do it make a code where all H2 tags from the_content are pulled and read out to create a table of content. I've done this succesfully with the code below: function ...
branco holtslag's user avatar
-3 votes
0 answers
40 views

Array of Strings using (forEach) [closed]

In the course of learning java, I have come across the method ** (for each), which has caught my attention. However, I would like to know if I can modify it to allow the user to input an array of ...
Ebrahim salem's user avatar
0 votes
1 answer
80 views

Handle programmatically adding Divider() inside ForEach loop

I am looking at ways to improve adding a Divider() in a SwiftUI view programmatically. The example code here does what I want visually, but I am thinking there should be a better way. The goal of what ...
tkess17's user avatar
  • 33
-2 votes
0 answers
12 views

make calculations to calculate the number of items and the price of the desired item, in laravel?

I want to make calculations to calculate the number of items and the price of these items, but I'm confused about how because I store the data using foreach in the controller I'm confused how to make ...
Berlina Shobirah's user avatar
0 votes
0 answers
26 views

Why is my For Each loop not looping through all worksheets in VBA? [duplicate]

I'm trying to loop a bunch of code through all worksheets in a workbook. However it is only applying to the sheet I am on when I trigger the macro. I think that this may be caused by the fact that I ...
Drezden's user avatar
0 votes
1 answer
20 views

nested foreach for time table getting foreach() argument must be of type array|object, string given

I want to make a weekly schedule time table using foreach with given variable, but I got an error saying foreach() argument must be of type array|object, string given, I don't know where I was wrong, ...
M. Rivaldi Anwar Putra's user avatar
1 vote
1 answer
79 views

Issue in nested iteration issue in Azure Logic Apps - foreach loop

I hope this message finds you well. I am writing to bring to your attention an issue I have encountered while working with nested iterations in Azure Logic Apps. I believe there might be a bug or ...
Shubham Vashisht's user avatar
0 votes
0 answers
7 views

Error when using foreach loop to filter data dynamically based on user selection from dropdown list in cshtml

I am trying to using foreach loop to get data that is filtered dynamically. I have a dropdownlist and after user select the year from it, the selected year will be used as filter to show data in the ...
Hailan Z.'s user avatar
0 votes
0 answers
26 views

Issue with "Loop through all the sheets" with VBA [duplicate]

Issue with "Loop through all the sheets" with VBA I would like to check on all sheets that is there a cell in the 6nd row which contains "text". The code is the following but it ...
FoFE's user avatar
  • 45
0 votes
1 answer
43 views

How to loop foreach inside loop div [closed]

i want to create and tabel every showing 3 data from db and continue the next db. exp swiper 1 : (1,2,3) , Swiper 2 : (4,5,6) etc. is it possible to loop a div and have a foreach in it? or any ...
daun babadotan's user avatar
0 votes
0 answers
29 views

PHP PDO foreach not working within function [duplicate]

Attempting to create a template for the header element of my PHP site within a functions page. I can get the template to function correctly using heredoc but when I try and include a foreach within ...
James's user avatar
  • 1
0 votes
3 answers
43 views

wrapping a parent element around every 3 elements

I'm just trying to wrap a div w class of slide around every 3 divs with a class of search-audio. the one error i'm running into is that it's saying elem.parentElement is undefined... So part works ...
Emily Childers's user avatar
-1 votes
0 answers
15 views

How to reference and use multiple divs Independently of each other

My first post here so I'll try my best, I'm trying to make a calendar/ checkbox where I can track my consistency in things,Pic here for reference-->> enter image description here. All the boxes ...
ibaiba2112's user avatar
1 vote
1 answer
40 views

Create Table from array with only Javascript

I've been trying for about 2 days now to create a table from an array with pure Javascript. What I want in the future is to be able to pull data from a database and allow JS to create the table for me....
Ruzzy100's user avatar
-2 votes
0 answers
62 views

why are my newly selected picker values not showing in the View?

I have an array of golf tee off groups and I am presenting them in a list and am using a picker to select the starting hole for each golf group object. The following example should be reproducible. I'...
phil's user avatar
  • 989
0 votes
2 answers
40 views

Parallel computing for mediation analyses - foreach and dopar Error not finding assigned object within loop

I am trying to iterate mediation analyses with a large number of variable combinations (around 700.000 combinations). Thus far I have generated code to produce the exact output that I need and I have ...
freutopia's user avatar
-1 votes
0 answers
10 views

"Getting 'Undefined variable: items' error in Laravel project" [duplicate]

I'm facing some issues with a project built with Laravel I want the items in the dropdown menu to be able to display the value I select in the dropdown menu please help me. I've tried many solutions ...
Muhammad Zainal Arifin's user avatar
0 votes
0 answers
31 views

if checkbox is checked then take url from html data-url and open it in new tab with window.open()

<section class="main-checkboxes-section"> <div class="select-popup-divs"> <input id="check-1" type="checkbox" class="css-checkbox" ...
over-heaven's user avatar
0 votes
1 answer
39 views

How to replace a ForEach when there's only on item in SwiftUI?

I wonder if it's possible to replace the ForEach below as I only have one "product" into the products array? if !storeManager.products.isEmpty { ForEach(storeManager.products) { product ...
Alexnnd's user avatar
  • 287
1 vote
1 answer
21 views

Prevent height of grid item from expanding all available height

My code is generally working fine but there is one small issue. Everytime that I want to toggle a particular players' box the box expands (as it should) but then the other players' boxes that are in ...
TheComic2222's user avatar
0 votes
2 answers
55 views

Run forEach in order of value inside of loop

I have a forEach loop that calls a function for each element in the loop. One of the elements is an element called index that has values as such: "fields": [ { ...
nb_nb_nb's user avatar
  • 1,175
1 vote
2 answers
35 views

How to auto post php form imported data

1.txt aaaaaaaaaa bbbbbbbbbb cccccccccc ...... Code: `$post_data = array( 'user_data' => array( 'username' => $username, 'password' => $password, 'max_connections' => $max_connections,...
XASTRA's user avatar
  • 21
0 votes
1 answer
28 views

How to limit return in a jQuery for each loop?

I am using jQuery to pull data from an API, and I cannot limit the results through a query paramter. My code is this - $.ajax({ method: 'GET', url: url }).done(function (data, status, xhr) { ...
jfc's user avatar
  • 361
0 votes
2 answers
46 views

Test if a string matches with any RegExp element of an array in JS

I'm trying to develop a modular function that check if a string matches with a slice of RegExp. As a matter of context: // Object containing regular expressions const regex = { uppercase: /(?=.*[A-...
vulopez's user avatar
0 votes
0 answers
44 views

Powershell - Foreach Loop on JSON Data - How to Include Child Objects in Output IF Exists

I have a JSON dataset similar to the following, where in some objects we have additional data that is not present on other objects. "Menu":[ "Item 1"{ "ID": "...
user3342019's user avatar
1 vote
1 answer
43 views

Pass regex to graphQL query using axios

I have a graphQL mutation that I am running using axios inside of a forEach loop. One of the values I am passing is a regex rule as a string but when I run my function, I get the following errors when ...
nb_nb_nb's user avatar
  • 1,175
0 votes
0 answers
48 views

Java throwing class cast exception even if types are correct

I was learning about Matrix Variables in spring boot but I encountered problems while extracting the data. @GetMapping(value = "/{query}/plan", produces = {"application/xml"}) ...
Sandeep Shiven's user avatar
0 votes
1 answer
42 views

Why does change in the model not reflect in child views?

struct ContentView: View { @StateObject var cntrl=ContentViewController2() var body: some View { VStack { ItemsDisplay(items: cntrl.model.items, handler: cntrl....
matyasl's user avatar
  • 295
1 vote
1 answer
34 views

Pass array to graphQL query using axios

I have a graphQL mutation that I am running using axios inside of a forEach loop. One of the values I am passing is an array but when I run my function, the function just gets stuck there and does not ...
nb_nb_nb's user avatar
  • 1,175
0 votes
0 answers
22 views

Excel: For Each loop to copy and paste to form a table

I have a file that allows for 2 drop down lists to be selected and return the corresponding results. Now I want to be able to copy and paste all the results of all possible selections from the lists ...
Malcolm McDermid's user avatar
0 votes
1 answer
43 views

Xsl: how to optimize for-each loops

Is there an easy way to optimize the following for-each loops? There are 3 for-each loops. Actually it is not very performant ;-) The bottleneck is the second and third foreach Must be Xsl1.0! <...
Marcus Steinbauer's user avatar
1 vote
2 answers
61 views

JavaScript forEach and 3 buttons

I'm a beginner in JavaScript and I have a problem. I'm building a randomizing page, where I use 3 arrays and 3 buttons. I want it to expand with the answer (button 1 - array no1, button 2 - array no2, ...
Shaggy6566's user avatar
0 votes
1 answer
35 views

Where is the implementation of abstract forEach() of Stream interface?

Iterable forEach():[No Confusion] As I know that forEach() is a default method and defined inside Iterable Interface. default void forEach(Consumer<? super T> action) { Objects....
PANKAJ DUBEY's user avatar
0 votes
1 answer
48 views

How to pass two sets of array from look up activity into For each activity and later how to refer these two arrays inside for each loop activity

I have pipeline which triggers the powerBI refresh from ADF and waits for the results of powerBI refresh and sends an email if refresh was success or failure, now I want to put this pipeline in ...
vidya kanmus's user avatar
0 votes
0 answers
30 views

How to use a forEach loop to modify array elements with values from another array [duplicate]

I am having trouble understanding how my foreach loop is operating. My goal is to iterate through 1 array of strings and add the current iterations string to the src attribute of an audio object in ...
Caleb Renfroe's user avatar
-1 votes
1 answer
23 views

I want to execute loop depending on the Json Extractor & In loop i want to add another json extractor in Json Expression according to loop iteration

I have added one sampler & get the response of it. In Response there is Big Json array, like There are multiple AppObjects array & In one AppObjects array there are multiple DSQ array. Now i ...
Krina Modi's user avatar
-2 votes
1 answer
64 views

How to use for_each loop to cycle kv pairs in terraform templates?

We have a Hashistack infrastructure: Nomad, Vault, Consul... I want to deploy an app with a Terraform. The app has it's variables in Vault's kv store. I have a problem understanding how to make key-...
Gutleib's user avatar
0 votes
1 answer
59 views

How to create for each of the MS Access datatables in vb.net

How to create for each of the MS Access datatables in vb.net?. So I want to appear one by one according to "EMPID" in print preview. should appear in those print preview based on one row ...
user18's user avatar
  • 5
1 vote
1 answer
40 views

forEach loop in JS is only selecting one image from my gallery?

I have a image gallery with some JavaScript that shows a specific image from the gallery in a larger format whenever you click on a magnifying glass icon. The button itself seems to work fine but it ...
Mauro's user avatar
  • 13
0 votes
2 answers
27 views

wire:click.prevent function not working inside foreach looping

I making search function with ajax. After fetch data with foreach loop , the result component did not support livewire (wire:click.prevent). Other tag that outside of the looping is working fine . ...
yan naing's user avatar
-1 votes
0 answers
27 views

PHP Exclude Array Ids from selecting in the database - Procedural Way [duplicate]

I am trying to exclude Array Ids from selecting in the database I have 3 categories in the database, when I not selecting IDs [3,4] , it's not working and returns all items with the result. The ...
wowoffer's user avatar
-1 votes
2 answers
39 views

Parse and format the Data in bash or C-shell [closed]

I have the input data in below format from command and I need to parse it using foreach loop or awk or any efficient technique to get desired output as shown below. Input Data: General Information ...
sandy's user avatar
  • 55
0 votes
1 answer
100 views

Change Background Color of selected button item swiftui in foreach

View : struct SubCatProductView: View { @StateObject private var vm = SubCategoryViewModel() @State private var hasError = false @State private var selectedSubCat = "&...
SasidharanIOS's user avatar
0 votes
0 answers
26 views

Why doesn't my foreach loop execute an Rcpp function in parallel?

I seem to have the same problem as this poster from 8 years ago: Rcpp sourceCpp with parallel foreach. Let me describe this in the abstract first: I have defined an Rcpp function with cppFunction, let'...
user1657021's user avatar

1
2 3 4 5
511