iteration

Is there a way to have parallel for-each loops?

Let's say I have 2 lists in Python and I want to loop through each one in parallel - e.g. do something with element 1 for both lists, do something with element 2 for both lists... I know that I can do this by using an index: for listIndex in range(len(list1)): doSomething(list1[listIndex]) doSomething(list2[listIndex]) But is th...

Iterate textboxes in order by name, inside a tab control

I have a bunch of textboxes, about 150 to be exact. They are inside different tabs of a tab control, and are not in order by name on screen. They are named simply textBox1, textBox2, textBox3... I would like to be able to iterate them in order by name and not by how they appear on the form. How would I got about doing this? ...

How can I use Array#delete while iterating over the array?

I have an array that I want to iterate over and delete some of the elements. This doesn't work: a = [1, 2, 3, 4, 5] a.each do |x| next if x < 3 a.delete x # do something with x end a #=> [1, 2, 4] I want a to be [1, 2]. How can I get around this? ...

RoR noob: How do I access a counter inside an iteration?

My google skills are failing me big time. If I have a standary RoR loop like this: <% @notes.each do |q| %> <% end> How do I access a loop counter from inside the loop? Thanks for reading. ...

How to increase number of iterations from within the loop in php?

Hi, I'm working on custom pagination system and encountered following problem. When one of the elements is filtered out of the set, the size of the final array is smaller than needed. Therefore I'm looking for a solution to increase the number of iterations from within the loop to always get array consisting of 50 elements. $limit = 50...

Iteration,concurrentModifcationException in Java

Hi I'm using a enhanced for loop over an ArrayList and wanted to remove some elements that contain a particular value. When I try to do this I get the above exception. I've had a look around and it seems using a enhanced for loop while modifying the collection is a bad idea. How else would I go about this? thanks for any help. ...

for vs each in Ruby

I just had a quick question regarding loops in Ruby. Is there a difference between these two ways of iterating through a collection? # way 1 @collection.each do |item| # do whatever end # way 2 for item in @collection # do whatever end Just wondering if these are exactly the same or if maybe there's a subtle difference (possibly ...

Is order of iteration for Qt’s QHash repeatable across multiple identical runs of a program?

Assume that a program is run several times in identical fashion. In each run, the same set of objects is insert into a QHash in the same insertion order; then the objects in the QHash are iterated. The question is will the objects be iterated in the same order in each run of the program? ...

Algorithm to iterate through sample space of numbers

I hope this isn't a dupe, but it's hard to boil down the problem into keywords! This is always something that I've wondered about. Let's say you have a black box that takes n integers as an input (where n > 1). Given that there is a bounds on the integer values, how would you go about writing an algorithm that will push the entire sampl...

java hashmap key iteration

Is there any way to iterate through a java Hashmap and print out all the values for every key that is a part of the Hashmap? ...

how to iterate all array element starting from a random index.

I was wondering if is it possible to iterate trough all arrays elements starting from any of its elements without pre-sorting the array. just to be clearer suppose i have the array of 5 elements: 0 1 2 3 4 i want to read all elements starting from one of their index like: 2 3 4 0 1 or 4 0 1 2 3 the idea is to keep the element orde...

Kohanaphp v3 execute()

excecute() method always return an "informational" object after use current() method i get an array always. How can i obtain an object (with objects) to iterate like this, (no ORM): foreach($obj as $o) { echo $o->name; echo $o->email; } Instead of using current, next, etc. ...

Whats the most efficient way of doing this?

Hey guys, I've got an array array of size N. For every 3 indexes in it I want to take them out and declare and assign those values to another array of size 3. I then want to go back to that array and take the next 3 and put it in a different array of size 3. I'll iterate like this for 3 different arrays of size 3 a1,a2,a3 once this is d...

returning a std::string with an vector

hi, I'm trying to get "CMtoaPlugin::listArnoldNodes()" to return an "array" of strings std::vector<std::string> ArnoldNodes = CMtoaPlugin::listArnoldNodes(); std::vector<std::string>::iterator it; for ( it=ArnoldNodes.begin() ; it < ArnoldNodes.end(); it++ ) { printf("initialize shader %s\n", *it); } but this is ...

Working examples of EM::Iterator

Does anyone have any working examples of EM::Iterator? The only examples I can find seem to be copies of (or point back to): http://yardoc.org/docs/eventmachine-eventmachine/EventMachine/Iterator I don't see any instances of EM::Iterator in EventMachine's Rdoc, so I'm not sure if it's an old class that has been removed or not. I gen...

Iterating through Expando's Dynamic properties in Django Templates

I'm trying to iterate through an Expando-Model's dynamic properties in order to output them all. Is there a way of doing this other than creating your own method like such: class Event(db.Expando): platform = db.ReferenceProperty(Platform) date = db.DateTimeProperty() def getValues(self): return self._dynamic_proper...

help sorting a dictionary into another dictionary

I have a dictionary (index2) of 3-item lists, organized by key from 0-150 or so. I need to sort it into another dictionary, with the following constraints: 1.) all items attached to one key must stay together in the second dictionary 2.) length of items in the second dictionary must all be the same. To help with this one, I divided the t...

Iteration order of sets in Python

If I have two identical sets, meaning a == b gives me True, will they have the same iteration order? I tried it, and it works: >>> foo = set("abc") >>> bar = set("abc") >>> zip(foo, bar) [('a', 'a'), ('c', 'c'), ('b', 'b')] My question is, was I lucky, or is this behavior guaranteed? ...

iterating through a list of records in a second (html) page, where the first page orders the results

I'm building this site using jsp / servlets on the backend. The first page (or "search" page) allows one to search for records from a table, and also allows the user to sort the records. The sorting mechanism is quite complicated, and is not just a matter of appending an "order by" to an sql query. The first page then also fills in t...

Indexing into arrays of arbitrary rank in C#

I need to iterate over an array of arbitrary rank. This is for both reading and writing, so GetEnumerator will not work. Array.SetValue(object, int) doesn't work on multidimensional arrays. Array.SetValue(object, params int[]) would require excessive arithmetic for iterating through the multidimensional space. It would also require dyna...