loops

Boolean infinite loop possible?

Is it possible to incur a infinite loop through the creation of a Boolean query (e.g. Library catalog or google search)? ...

How can I reduce the number of loops in this VIEW in Rails when using :collection?

I am using the :collection to go through all the Contacts that are part of a given Campaign. But within that Campaign I check for three different Models (each with their own partial). Feels like I am going through the list of Contacts 3x. How can I make this alot leaner? <h2>These are past due:</h2> <% @campaigns.each do |campaign| ...

How can we make a single dimension array to multidimensional Hierarchical ?

I have an single array of Hierarchical categories. Index of the array is the category_id like:: [8846] => Array ( [category_id] => 8846 [title] => Tsting two [description] => Tsting two [subtype] => categories [type] => object [level] => 2 [parent_category] => 8841 [tag...

javascript for (i = 0; i < XXX.length; i++) -> length question

for (m = 0; m < troopsCount.length; m++) { //FM_log(7,"i="+i+" m="+m); //FM_log(7,"tipoTropaPrioritaria[m] = "+tipoTropaPrioritaria[m]); //FM_log(7,"troopsCount[m] = "+troopsCount[m]); //FM_log(7,"availableTroops[m] = "+availableTroops[m]); if ((tipoTropaPr...

php for loop varable names

i got a code of 100-200 rules for making a table. but the whole time is happening the same. i got a variable $xm3, then i make a column . next row, i got $xm2 and make column. next row, i got $xm1 and make column. so my variables are going to $xm3, $xm2, $xm1, $xm0, $xp1, $xp2, $xp3. is there a way to make a forloop so i can fill $xm a...

Inspiration and influence of the else clause of loop statements?

Python loop statements may have an else clause which is executed if and only if the loop is not terminated by a break. In other words, when the condition becomes False (with while) or when the iterator is exhausted (with for). Does this loop-else construct originate from another language (either theoretical or actually implemented)? Ha...

Looping differences in Ruby using Range vs. Times

I'm trying to solve a Project Euler problem using Ruby, I used 4 different looping methods, the for-loop, times, range and upto method, however the times method only produces the expected answer, while the for-loop, range and upto method does not. I'm assuming that they are somewhat the same, but I found out it's not. Can someone please ...

WordPress: Using custom field to define posts to display in loop

Hi, I'm trying to use a custom field in which I input the post ID numbers of the posts I want to show, seperated by commas. For some reason though, only the first post of the series of the post IDs are displaying. Can someone help? The value of $nlPostIds is (minus the quotes): "1542,1534,1546". Here's the code... the most important pa...

nested for loop

Hello, Just learning Python and trying to do a nested for loop. What I'd like to do in the end is place a bunch of email addresses in a file and have this script find the info, like the sending IP of mail ID. For now i'm testing it on my /var/log/auth.log file Here is my code so far: #!/usr/bin/python # this section puts emails from ...

Deleting While Iterating in Ruby?

I'm iterating over a very large set of strings, which iterates over a smaller set of strings. Due to the size, this method takes a while to do, so to speed it up, I'm trying to delete the strings from the smaller set that no longer needs to be used as it goes along. Below is my current code: Ms::Fasta.foreach(@database) do |entry| ...

how to stop a javascript loop for a particular interval of time?

i am using javascript for loop, to loop through a particular array and alert it's value. I want that after every alert it should stop for 30 seconds and then continue...till the end of loop. my code goes here.. for(var i=0; i<valArray.lenght; i++) { alert("The value ="+valArray[i]); //stop for 30seconds.. ...

What is the best way of determining a loop invariant?

When using formal aspects to create some code is there a generic method of determining a loop invariant or will it be completely different depending on the problem? ...

PHP: Infinity loop and Time Limit!

Hi, I have a piece of code that fetches data by giving it an ID. If I give it an ID of 1230 for example, the code fetches an article data with an ID of 1230 from a web site (external) and insert it into a DB. Now, the problem is that I need to fetch all the articles, lets say from ID 00001 to 99999. If a do a 'for' loop, after 60 second...

Stupid newbie c++ two-dimensional array problem.

I've no idea if this is too newbie or generic for stackoverlflow. Apologies if that's the case, I don't intend to waste time. I've just started working through C++ Primer Plus and I've hit a little stump. This is probably super laughable but: const int MONTHS = 12; const int YEARS = 3; int sales[YEARS][MONTHS] = {0}; const string mont...

AS3 Random repeat x seconds function

Hi, I have the following function: function update(e:Event):void { var val:Number = Math.random() * 120; rgb.r.x = rgb.r.y = val; rgb.b.x = rgb.b.y = -val; } And im looping it with: stage.addEventListener(Event.ENTER_FRAME, update); But what I need to do would be something like: Random number between 1 and 20 If the number is > 1...

How to fill many texbox by using loop function in VBA

Hi ! I made a user interface in VBA with many textbox. I read an excel sheet and I put all the value of this one in all the textbox of my user inteface. So the user can modify the values and then save it in the excel sheet. Because we can't name the textbox like array (textBox(1), textbox(2)....) this is hard to fill the textbox by usi...

iphone threading question - looping?

i want to have a background thread in my app that changes an image every 5 seconds for as long as the app is being run. Can someone point me in the direction of how this works? I am new to threads. ...

Pascal's repeat... until vs. C's do... while

In C there is a do while loop and pascal's (almost) equivalent is the repeat until loop, but there is a small difference between the two, while both structures will iterate at least once and check whether they need to do the loop again only in the end, in pascal you write the condition that need to met to terminate the loop (REPEAT UNTIL...

Avoid the use of loops (for) with R

Hi, I'm working with R and I have a code like this: for (i in 1:10) for (j in 1:100) if (data[i] == paths[j,1]) cluster[i,4] <- paths[j,2] where : data is a vector with 100 rows and 1 column paths is a matrix with 100 rows and 5 columns cluster is a matrix with 100 rows and 5 columns My question is: how cou...

Problem with loop MATLAB

no time scores 1 10 123 2 11 22 3 12 22 4 50 55 5 60 22 6 70 66 . . . . . . n n n Above a the content of my txt file (thousand of lines). 1st column - number of samples 2nd column - time (from beginning to end ->accumulated) 3rd column - scores I wanted to create a new file...