Bash foreach loop

Something like this would do: xargs cat <filenames.txt The xargs program reads its standard input, and for each line of input runs the cat program with the input lines as argument(s). If you really want to do this in a loop, you can: for fn in `cat filenames.txt`; do echo “the next file is $fn” … Read more

Advantages of std::for_each over for loop

The nice thing with C++11 (previously called C++0x), is that this tiresome debate will be settled. I mean, no one in their right mind, who wants to iterate over a whole collection, will still use this for(auto it = collection.begin(); it != collection.end() ; ++it) { foo(*it); } Or this for_each(collection.begin(), collection.end(), [](Element& e) { … Read more

Java 8 forEach with index [duplicate]

Since you are iterating over an indexable collection (lists, etc.), I presume that you can then just iterate with the indices of the elements: IntStream.range(0, params.size()) .forEach(idx -> query.bind( idx, params.get(idx) ) ) ; The resulting code is similar to iterating a list with the classic i++-style for loop, except with easier parallelizability (assuming, of … Read more

JavaScript foreach loop on an associative array object

The .length property only tracks properties with numeric indexes (keys). You’re using strings for keys. You can do this: var arr_jq_TabContents = {}; // no need for an array arr_jq_TabContents[“Main”] = jq_TabContents_Main; arr_jq_TabContents[“Guide”] = jq_TabContents_Guide; arr_jq_TabContents[“Articles”] = jq_TabContents_Articles; arr_jq_TabContents[“Forum”] = jq_TabContents_Forum; for (var key in arr_jq_TabContents) { console.log(arr_jq_TabContents[key]); } To be safe, it’s a good … Read more

Is there a way to iterate over a dictionary?

Yes, NSDictionary supports fast enumeration. With Objective-C 2.0, you can do this: // To print out all key-value pairs in the NSDictionary myDict for(id key in myDict) NSLog(@”key=%@ value=%@”, key, [myDict objectForKey:key]); The alternate method (which you have to use if you’re targeting Mac OS X pre-10.5, but you can still use on 10.5 and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)