foreach

How do I fix this Java generics wildcard error?

In this question, TofuBeer was having problems creating a genericized IterableEnumeration. The answer came from jcrossley3 pointing to this link http://www.javaspecialists.eu/archive/Issue107.html which pretty much solved the problem. There is still one thing I don't get. The real problem, as effectively pointed out by erickson, was ...

Continue in while inside foreach

In the following C# code snippet I have a 'while' loop inside a 'foreach' loop and I wish to jump to the next item in 'foreach' when a certain condition occurs. foreach (string objectName in this.ObjectNames) { // Line to jump to when this.MoveToNextObject is true. this.ExecuteSomeCode(); while (this.boolValue) { ...

What is the special case with the foreach loop that eliminates bounds checking?

What is the special case with the foreach/for loop that eliminates bounds checking? Also which bounds checking is it? ...

What's the most efficient way to do these two foreach-loops?

Hi folks, i'm not sure this is the best way to do the following code. I'm not sold on a foreach inside another foreach. Could this be done *better** with Linq? *I understand that better could be either a) more performant b) easier to read / more elegant c) all of the above NOTE: .NET 3.5 solutions accepted :) NOTE2: the two IList's ...

Erroneous Data Retrieved From ListView

I am having some trouble with my program logic that loops through a collection of data that exists in two separate ListViews. After looping though and extracting the data from the ListView, I then add everything into a comma delimited text file (CLOSEULDCONFIG.TXT). The first time that I execute this logic, everything works as it shoul...

Is Java foreach iteration order over primitives precisely defined?

Example code: int a[] = new double[]{0, 1, 2, 3}; int result = 0; for (int i : a) result += i; Is the loop guaranteed to iterate across a[0], a[1], a[2], a[3] in that order? I strongly believe the answer is yes, but this page seems to not unambiguously state order. Got a solid reference? ...

Why is std::for_each a non-modifying sequence operation?

I just read in the C++ standard that std::for_each is a non-modifying sequence operation, along with find, search and so on. Does that mean that the function applied to each element should not modify them? Why is that? What could possibly go wrong? Here is a sample code, where the sequence is modified. Can you see anything wrong with it...

Error Showing Up in Server Logs...How Do I Stop It?

I'm getting an error and I've googled everything I can think of with barely any insights. Maybe you can help with a fresh set of eyes. I have a function that returns an array of objects. The code that calls this function then loops through this array and does what it needs to do with each object. It seems to work visually when it spits ...

Sort order when using foreach on an array, list etc.

When iterating through an array using foreach, are there any guaranties that the order in which the elements are returned is the order array[0], array[1], array[2], ... I know this is how the Array class is implemented now but are there any guaranties for future versions of the framework? The same questions goes for List<>. ...

Null reference when performing foreach loop with Interfaces ASP.Net Cluster Environment

I have a List in a web control when the control creates it's child controls I perform a foreach loop through the list of fields as foreach (IField field in this._fields) { /* Do some work here */ } Localhost, out dev environment, and our staging environment everything is fine. But when we deploy to our dev cluster each "field" is...

Struts 2 URL Parameter inside foreach

Can someone explain to me why the following code results in the error: According to TLD or attribute directive in tag file, attribute value does not accept any expressions. It always breaks whenever I am trying to set the value dynamically for the parameter of the URL. `<%@ page contentType="text/html; charset=UTF-8" %>` <%@ taglib p...

Reproduce Smarty foreach with Php preg_match_all

Hi, I would like to reproduce the "Smarty foreach" comportment. The tpl file content is ($tplContent) : {foreach from=$tabMethodTest item=entry} /** * @todo Implement test{$entry.name}(). */ public function test{$entry.name}() { $this->markTestIncomplete("This test has not been implemented yet."); } {/fore...

Is it okay to use for_each to modify elements of a container in c++?

Duplicate: http://stackoverflow.com/questions/717509/is-it-ok-to-mutate-objects-with-stdforeach This is based on an earlier question which I can't seem to find anymore on stack overflow. Basically, is something like this legal? struct doSomething { void operator()(int& i) {++i;} }; int main() { std::vector<int> vec; vec.pu...

Why doesn't this for-each loop work?

In this code, why isn't my array initialised as I want it to? Is the for-each loop not designed to do that, or am I just not using it correctly? int[] array = new int[5]; //initialise array -> Doesn't work! Array still full of 0's for(int i : array) i = 24; ...

Emacs indentation of the for each statement in C++

I'm trying to get emacs to correctly format the "for each" construct in c++. I want the braces to be lined up with the f in for in both of the following examples: for each(Type a in b) { //^c^s shows substatement-open //... do stuff } for( ; ; ) { //^c^s shows substatement-open //... do stuff } In b...

Python strange behavior in for loop or lists

Hi, I'm currently developing a program in python and I just noticed that something was wrong with the foreach loop in the language, or maybe the list structure. I'll just give a generic example of my problem to simplify, since I get the same erroneous behavior on both my program and my generic example: x = [1,2,2,2,2] for i in x: x...

What's wrong with my PHP array?

$genreList; function directorGen($array) { foreach($array as $value) { $genreList[] = $value; } } //later.. directorGen($title->genres()); This code results in a NULL array. If I replace $genreList[] = $value with echo $value everything prints out like expected. Any ideas? ...

Why is List<T>.ForEach faster than standard foreach?

Consider this: Requisite: //The alphabet from a-z List<char> letterRange = Enumerable.Range('a', 'z' - 'a' + 1) .Select(i => (Char)i).ToList(); //97 - 122 + 1 = 26 letters/iterations Standard foreach: foreach (var range in letterRange) { Console.Write(range + ","); } Console.Write("\n"); Inbuilt foreach: letterRange.ForEach(r...

Is there a parameter I can use in Java that works with all for-each loops?

Suppose I've got a method that accepts an array and processes each element in it using Java's built in for-each loop, like this: public static void myFun(SomeClass[] arr) { for (SomeClass sc : arr) { // Stuff is processed here } } This works just fine, but now I want to be able to pass the same method a List<SomeClass>...

How to use BOOST_FOREACH with two std::maps?

I have code that looks essentially like this: std::map<int, int> map1, map2; BOOST_FOREACH(int i, map1) { // do steps 1-5 here... } BOOST_FOREACH(int i, map2) { // do steps 1-5 (identical to above) here... } Is there any way to concatenate the maps to eliminate the duplicate code in the second loop? Or a way to extend BOOST_FO...