loops

Prototype add event listener

Hey, For some reason, when I try assigning a actionlisetner to the list elements the value does not stick. Here is what I mean: Event.observe(window, 'load', function() { for(i = 1; i <= $$('ul#review_list li').length; i++) { $('cover_' + i).observe('click', function(event) { alert(i); }); } }); So there are...

Using foreach to update fields in a mysql databse based on another query

Ok I really should be be clued up on this now but its a bit late here in england and I was wondering if someone could point out the obvious to me. I have to do a first query which is SELECT * from table WHERE NOT column=0, and use the results from that to do a foreach loop something like below. foreach($results as $result) { $nox = $r...

loop through two variable in Haskell

Hi, What is the haskell way to do this? for (int i = 0 ; i < 1000 ; i++) for (int j = 0 ; j < 1000 ; j++) ret = foo(i , j ) #I need the return value. More background: I am solving euler problem 27 , and I have got: value a b = let l = length $ takeWhile (isPrime) $ map (\n->n^2 + a * n + b) [0...

Canceling a While loop prematurely.

I'm using a While loop that loops a certain number of cycles (1-576) based on a value entered by a user. It's activated by the user clicking a "Start" button, But I would like it to be able to be canceled using, preferably, the "Escape" key. However, when the loop is going I can't get the program to recognize any keypresses. Private Su...

Syntax for a single-line BASH infinite while loop

Having trouble coming up with the right combination of semicolons and/or braces. I'd like to do this, but as a one-liner from the command line: while [ 1 ] do foo sleep 2 done ...

Loop or sort for layered draw?

Assuming a collection of objects, each of which needs to be drawn at a specific layer, at what point would it (or ever) be better to sort each object by layer rather than looping multiple times and drawing a layer at each pass? More importantly how would you arrive at this conclusion? Bonus points for a sort algorithm you would use if ...

PHP array printing using a loop

If I know the length of an array, how do I print each of its values in a loop? ...

How to get all filtered data rows in excel (with hidden columns)?

My data sheet has filters and hidden columns. When filter(s) applies, I need to loop through all filtered data. I use: Excel.Range visibleRange = this.UsedRange.SpecialCells(XlCellType.xlCellTypeVisible, missing) as Excel.Range; Now visibleRange.Rows.Count is 0; use foreach loop "foreach(Excel.Range row in visibleRange.Row)" row d...

Why does my Perl regex cause an infinite loop?

I have some code that grabs the "between" of some text; specifically, between a foo $someword and the next foo $someword. However, what happens is it gets stuck at the first "between" and somehow the internal string position doesn't get incremented. The input data is a text file with newlines here and there: they are rather irrelevant,...

JQuery fade with loop and delay

Hello, I have 2 Divs stacked on top of each other. I need a really simple function that will: a) Wait for 3 seconds and then b) FadeOut the top Div to reveal the second Div c) Wait 3 seconds again and then d) FadeIn the top Div again e) Loop back again Can anyone offer any advice? Many thanks ...

JQuery .each() callback function doesn't run on each iteration/loop

Here's what should happen. 1. Get the rel attribute of the clicked link 2. For every div with class 'entry': (i)Get its 'left' position (ii) Calculate its outer height (iii)Loop through all instances of 'a.tag_filter'. If it finds the same string in the 'rel' as the one oringinally clicked on then add 1 to 'V' and break out o...

Why do some programming languages restrict you from editing the array you're looping through?

Pseudo-code: for each x in someArray { // possibly add an element to someArray } I forget the name of the exception this throws in some languages. I'm curious to know why some languages prohibit this use case, whereas other languages allow it. Are the allowing languages unsafe -- open to some pitfall? Or are the prohibiting...

Javascript event handling and flow control

I'm attempting to build a webpage that loads depending on the input provided. I'm having some trouble wrapping my head around event handling in javascript, basically. Coming from python, if I wanted to wait for a specific keyboard input before moving on to the next object to display, I would create a while loop and put a key listener ins...

How does Fast Enumeration (looping) work in Objective-C? (ie: for (NSString *aString in aDictionary)...)

I'm working on implementing a customized searchBar for a fairly complex table and have come across this code pattern AGAIN. This is a sample from the Beginning iPhone Development book: - (void)handleSearchForTerm:(NSString *)searchTerm { NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init]; [self resetSearch]; for (NSStrin...

'for' loop and typecasting hell ! (PHP)

//matches[0] holds some preg_match'ed values for($i=0;$i<count($matches[0]);$i++) { $price = $matches[0][$i]; //a**uto type casting to (float) returns 0 for $price. Tried it for values greater than 1 too.** //echo gettype($price); $price = $price + 0.01; **//Returns 0 + 0.01 instead of the right answer** //**even after remov...

assigning data in a new table to an existing foreign key in a for loop

Hi there, I was wondering if there was a way to assign new data in a table to an existing foreign key. For example if i use the following loop to assign randomly generated numbers to columns in the customer table, how would I be able to link cust_id, which I have assigned as a foreign key in the Sales table, with new data created each ti...

Looping through WPF ListView DateTemplate Items

I have a ListView in a Windows Form that I bind a list of objects to on the creation of the form. What I would like to do is on a button click loop through the items that were created and change their IsEnabled property to false. I've tried two methods and neither were particularly successful. Can anyone help fix these up and/or sugge...

How to create a moving clouds using jQuery?

My previous javascript on moving clouds is not compatible with jQuery, I need a better codes that allows of looping and moving div. ...

looping through elements with jQuery based on name attribute rather than id

Thanks for taking the time to read this. I have an unknown number of (dynamically inserted) input elements in a form, to each of which I want to attach the datepicker widget included in jQuery UI. All of the input elements that I want to attach the datepicker to have a class of "date-pick". Obviously because we have more than one match...

Which loop to use, for or do/while?

Using C# (or VB.NET) which loop (for loop or do/while loop) should be used when a counter is required? Does it make a difference if the loop should only iterate a set number of times or through a set range? Scenario A - The for loop for (int iLoop = 0; iLoop < int.MaxValue; iLoop++) { //Maybe do work here //Test criteria if (Cr...