foreach Questions

37

Solved

Is there some rare language construct I haven't encountered (like the few I've learned recently, some on Stack Overflow) in C# to get a value representing the current iteration of a foreach loop? ...
Mucous asked 4/9, 2008 at 1:38

5

Solved

One thing I have noticed with php, is that nothing is output to the screen until the script has stopped working. For the project I am working on I feed in a list of over 100 items and it performs a...
Abagael asked 29/7, 2009 at 15:28

2

Solved

What is the easiest way to iterate over all the key/value pairs of a java.util.Map in Java 5 and higher?
Nones asked 25/2, 2009 at 11:36

5

Solved

Student's names(String[]) and corresponding marks(int[]) are stored in different arrays. How may I iterate over both arrays together using for each loop in Java ? void list() { for(String s:st...
Barsac asked 11/10, 2013 at 12:56

5

Solved

I'm basically building my own parallel foreach pipeline function, using runspaces. My problem is: I call my function like this: somePipeline | MyNewForeachFunction { scriptBlockHere } | pipelineG...

11

Solved

I have the following code: $project.PropertyGroup | Foreach-Object { if($_.GetAttribute('Condition').Trim() -eq $propertyGroupConditionName.Trim()) { $a = $project.RemoveChild($_); Write-Host $_...
Centralia asked 23/4, 2012 at 9:32

3

Solved

I'm trying to move from BATCH into PowerShell and I am trying to convert my own scripts. My problem is with ranges in loop: my original BATCH script was like for /L %%U in (123,2,323) do ECHO %%...
Caramelize asked 14/6, 2018 at 4:0

5

Solved

Construction is this: <!-- projects list --> {if !empty($userObjects)} <select id="projects-list" tabindex="1" name="project"> {if !isset($selected)}<option value="0">Choose p...
Guanabara asked 27/12, 2012 at 14:49

25

Solved

I have an ArrayList that I want to iterate over. While iterating over it I have to remove elements at the same time. Obviously this throws a java.util.ConcurrentModificationException. What is the ...
Geostatics asked 12/11, 2011 at 13:22

3

Solved

I have the following proxy: const p = new Proxy({ [Symbol.iterator]: Array.prototype.values, forEach: Array.prototype.forEach, }, { get(target, property) { if (property === '0') return 'one'; ...
Garges asked 3/11, 2016 at 18:35

3

Solved

I am porting some code to Parallel.ForEach and got an error with a continue I have in the code. Is there something equivalent I can use in a Parallel.ForEach functionally equivalent to continue in ...

14

Almost all languages have a foreach loop or something similar. Does C have one? Can you post some example code?
Horus asked 30/12, 2008 at 17:39

6

Solved

I have a loop like this: @foreach($data as $d) @if(condition==true) {{$d}} // Here I want to break the loop in above condition true. @endif @endforeach I want to break the loop after data di...
Wanting asked 19/7, 2017 at 11:43

2

Solved

Currently I am doing a small refactor in our infrastructure. My current version of my project is similar to the following: And I am trying to use for_each to reuse variables. resource "google_...
Armond asked 6/12, 2021 at 22:13

10

Solved

Which code snippet will give better performance? The below code segments were written in C#. 1. for(int tempCount=0;tempCount<list.count;tempcount++) { if(list[tempCount].value==value) { // S...
Distended asked 14/7, 2009 at 11:16

4

Solved

So, I have a bug to remove foreach (XElement x in items.Elements("x")) { XElement result = webservice.method(x); if (/*condition based on values in result*/) { x.Remove(); } } The proble...
Portraitist asked 7/10, 2009 at 16:47

41

Solved

How can I loop through all the entries in an array using JavaScript?
Hispaniola asked 17/2, 2012 at 13:51

2

Solved

EDIT I've changed the title of the question to reflect the issue I had but also an answer on how to achieve this easily. I am trying to make the 2nd method to return Task<TResult> instea...
Archiplasm asked 4/10, 2013 at 19:28

5

Solved

I have this code which is supposed to iterate over each item in an array, removing items based on some condition: //iterate over all items in an array //if the item is "b", remove it. var arra...
Polytheism asked 16/2, 2014 at 13:19

15

Solved

When using external iteration over an Iterable we use break or return from enhanced for-each loop as: for (SomeObject obj : someObjects) { if (some_condition_met) { break; // or return obj } } ...
Thant asked 26/4, 2014 at 7:47

3

Solved

My code: Scenario 1 $newarray = array(); foreach($rows as $k => $v) { $newarray[$k] = $v; $newarray['newitem'] = 'Add this to existing object'; } echo json_encode($newarray); I tried t...
Prosthesis asked 27/10, 2016 at 8:44

3

Solved

I'm trying to list all buttons name from my form to list with code var v = new List<Form1>() { this }.ForEach(x => { x.GetType().Name.Contains(typeof(Button).Name); }); and always get ...
Merla asked 2/4, 2014 at 14:16

11

Solved

Wondering what would be a good method to get the first iteration on a foreach loop. I want to do something different on the first iteration. Is a conditional our best option on these cases?
Sheff asked 18/10, 2010 at 9:12

14

Solved

Something that really would like to know but never found out are shortcuts in PHP. I am currently coding a function with a foreach loop with just a single statement inside. I tried to omit the cur...
Whacky asked 4/1, 2012 at 11:45

3

Solved

I'm trying to compare these three but it seems only array_map works. $input = array( ' hello ','whsdf ',' lve you',' '); $input2 = array( ' hello ','whsdf ',' lve you',' '); $input3 = array( ' he...
Radiometeorograph asked 5/5, 2012 at 3:45

© 2022 - 2024 — McMap. All rights reserved.