iteration

Checking two dozen values, textboxes against datacolumns, algorithmically.

Okay big brains here's something that's more of a challenge than a requirement. I am a bit stumped. I usually just need a prod in the right direction, so get your prodding sticks ready. I have a tabcontrol covered in textboxes. I want to perform a check of the contents of all the textboxes during the SelectedIndexChanged event on a list...

Map an array modifying only elements matching a certain condition

In Ruby, what is the most expressive way to map an array in such a way that certain elements are modified and the others left untouched? This is a straight-forward way to do it: old_a = ["a", "b", "c"] # ["a", "b", "c"] new_a = old_a.map { |x| (x=="b" ? x+"!" : x) } # ["a", "b!", "c"] Omitting the "leave-alon...

What's the pattern to use for iterating over associated sets of values?

It's pretty common - especially as you try to make your code become more data-driven - to need to iterate over associated collections. For instance, I just finished writing a piece of code that looks like this: string[] entTypes = {"DOC", "CON", "BAL"}; string[] dateFields = {"DocDate", "ConUserDate", "BalDate"}; Debug.Assert(entTypes....

For-Each Loop AS3: Is the direction guaranteed?

I would like to know the iteration order for the Array, Dictionary and Object types in AS3, for both the for-each and the for-in loops. Also what factors can change the iteration order of these loop type combinations? For example I presume that using a for-each on an Array type always move from the first element to the last. For-each ca...

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? ...

flex 3 iterate through object values

hi, i have an object which represents a database table. I want to iterate through this object and print printing each value. What can i use to do this? i want to do this inside my mxml not actionscript for each object attribute i want to create an imput field ...

How do I access properties of a javascript object if I don't know the names?

Say you have a javascript object like this: var data = { Name: 'Property Name', Value: '0' }; You can access the properties by the property name: var name = data.Name; var value = data["Value"]; But is it possible to get these values if you don't know the name of the properties? Does the unordered nature of these properties make it...

algorithm comparison in C, what's the difference?

#define IMGX 8192 #define IMGY 8192 int red_freq[256]; char img[IMGY][IMGX][3]; main(){ int i, j; long long total; long long redness; for (i = 0; i < 256; i++) red_freq[i] = 0; for (i = 0; i < IMGY; i++) for (j = 0; j < IMGX; j++) red_freq[img[i][j][0]] += 1; total = 0; for (i = 0; i < 256; i++) to...

How to remove 'root' from iteration path in TFS queries

In Team foundation server I use Iterations / Areas. However when I run queries and select Iteration path as a column it always contains the 'root' iteration i.e. the name of the project. Is there a way how to get rid of it? It takes so much space (I unwisely chose long project name) and adds no extra information. ...

How can I properly parse my file? (Using break/continue)

I have the following data that looks like this for example: 34 foo 34 bar 34 qux 62 foo1 62 qux 78 qux These are sorted based on the first column. What I want to do is to process lines that starts with 34, but I also want the file iteration to quit after it finds no more 34s, without having have to scan through whole f...

How do I access consecutive elements in an IQueryable<T> object?

I need to access the current and previous element in an IQueryable object. If I had an int array, I would do the following: var array = new int[]{0,1,2,3,4}; for(var i = 1; i<array.Length ; i++) { method1(array[i-1], array[i]); } I don't know to do the same with IQueryable, since it does not implement IList. ...

Python "round robin"

Given multiple (x,y) ordered pairs, I want to compare distances between each one of them. So pretend I have a list of ordered pairs: pairs = [a,b,c,d,e,f] I have a function that takes two ordered pairs and find the distance between them: def distance(a,b): from math import sqrt as sqrt from math import pow as pow d1 = pow...

Mutilple javascript variable iterations with jquery

i have a form and would like to give users the ability to duplicate a group of fields as many times as necessary. With one group it iterates correctly but when I add a second group the "current" variable iterates collectively instead of being unique to each group... i tried changing all of the "current" to "newFieldset.current" but that ...

how to search arguments to find a match to the first argument in c language?

Okay I have to write a program that accepts 2 or more arguments and searches the second and remaining arguments for a matching argument. for example the output would be: ./a 3 h 4 9 3 3 found or ./a hsi and iash me 34 hsi hsi found So far I have this, and I'm pretty sure I've got a lot of junk in here that is useless in the...

Iterate over a python sequence in multiples of n?

How do I process the elements of a sequence in batches, idiomatically? For example, with the sequence "abcdef" and a batch size of 2, I would like to do something like the following: for x, y in "abcdef": print "%s%s\n" % (x, y) ab cd ef Of course, this doesn't work because it is expecting a single element from the list which its...

Why won't this PHP iteration work?

I want to make the results of a foreach loop into a string variable I can use later all over (so I don't need to paste the foreach loop everywhere). I have this: foreach($pairs as $d=>$m) { $orderedpairs .= "[".$d."],[".$m."]"+"<br />"; } echo $orderedpairs; If I substitute the assignment operator with "echo", it works fine, so the lo...

Why is "while" so popular in C#?

The question field is a bit too short to pose my real question. If anyone can recapitulate it better, please feel free. My real question is this: I'm reading a lot of other people's code in C# these days, and I have noticed that one particular form of iteration is widely spread, (see in code). My first question is: Are all these iter...

Recordset Iterating

I want to iterate through records returned from a MySQL database using Perl, but only ten records at a time. The reason is that the server component can only handle 10 items per request. For example: If the query returned 35 records then I have to send the data in 4 requests: Request # # of Records -------- ...

Ruby Iteration Question : Binary->Decimal Program

I am learning Ruby and thought of making a Binary->Decimal converter. It gets a binary string and converts to decimal equivalent. Is there a way to keep track of the current iteration step in ruby so that the variable 'x' can be removed? def convert(binary_string) decimal_equivalent = 0 x=0 binary_string.reverse.each_char...

How does "FOR" work in cmd batch file ?

I've been programming in dozens of languages for 20 years but I could never understand how "FOR" work in windows cmd shell batch file, no matter how hard I tried. I read http://www.amazon.com/Windows-Administration-Command-Line-Vista/dp/0470046163/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1241362727&amp;sr=8-1 http://www.ss64.com/nt/for...