loops

"Surround with"-template in Eclipse: foreach

I am new to Eclipse which I use primarily for Java. I have previously used IntelliJ Idea in which it is possible to select a variable which extends Iteratable (Collection, List etc) and have it produce a correct foreach loop. I know Eclipse does something similar with the foreach template, where it guesses which variable to iterate over...

jQuery get img source attributes from list and push into array

I have this thumbnail list and would like push the image paths (sources) into an array: tn_array <ul id="thumbnails"> <li><img src="somepath/tn/004.jpg" alt="fourth caption" /></a></li> <li><img src="somepath/tn/005.jpg" alt="fifth caption" /></a></li> <li><img src="somepath/tn/006.jpg" alt="sixth caption" /></a></li> </ul> ...

Group a string into 3s in a loop (python)

I have a nine character string and need to perform operations on groups of three characters in a loop. How would i achieve this in python? ...

How to optimize MATLAB loops?

I have been working lately on a number of iterative algorithms in MATLAB, and been getting hit hard by MATLAB's performance (or lack thereof) when it comes to loops. I'm aware of the benefit of vectorizing code when possible, but are there any tools for optimization when you need the loop for your algorithm? I am aware of the MEX-file ...

using cakephp, how do I display a series of data without using for each loops?

The application I'm building is a tennis draw, which has a list of matches organized by round. I've also given the matches a position number as a way to order them and manage matches that are at the top of the draw. In a 32 player draw there are 16 matches in the first round, with match positions ordered from 1 - 16. The draw is laid ou...

How to NOT use while() loops in verilog (for synthesis)?

I've gotten in the habit of developing a lot testbenches and use for() and while() loops for testing purpose. Thats fine. The problem is that I've taken this habit over to coding for circuits which should be synthesizable. XST and others refuse to synthesize code (without additional modification to synthesis parameters) such as: while (...

Better looping, for string manipulation (python)

If i have this code s = 'abcdefghi' for grp in (s[:3],s[3:6],s[6:]): print "'%s'"%(grp) total = calc_total(grp) if (grp==s[:3]): # more code than this p = total + random_value x1 = my_function(p) if (grp==s[3:6]): # more code than this p = total + x1 x2 = my_function(p) ...

Which loop do I use to ask if a user wants to continue the program in C#

I made a program that asks for input and returns a value. After, I want to ask if the user wants to continue. But I don't know what to use. ...

How to modify position of children inside loop in AS3

I'm trying to make a dynamic image gallery from and xml. From my tutorials, right now i've got it so it will constantly add the next thumbnail below the other, which is fine, but I'm trying to figure out how to make it that once it reaches a certain y coordinate, it will move the x coordinate over and stack them again. So that rather one...

Flash CS4 Actionscript 3.0 --- Make my script loop!

Here is my script... all I want to do is have it continuously loop! import fl.transitions.Tween; import fl.transitions.easing.*; yourwebsite_mc.visible=false; var uptodateFadeTween=new Tween(uptodate_mc,"alpha",Strong.easeOut,0,1,3,true); var uptodateRotateTween=new Tween(uptodate_mc,"rotation",Strong.easeOut,360,0,3,true); var uptod...

Response.Write in foreach live update?

Dear guys I have a foreach which imports data to our CMS. Now I want to display a message with the current row info after every run. I don't want that the information is comming after the whole procedure. The message have to come step by step. foreach() { // my import procedure Response.Write("row x updated"); } How can I do...

Unable to get set intersection to work

Sorry for the double post, I will update this question if I can't get things to work :) I am trying to compare two files. I will list the two file content: File 1 File 2 "d.complex.1" "d.complex.1" 1 4 5 5 48 ...

More efficient solution to loop nesting required

I am trying to compare two files. I will list the two file content: File 1 File 2 "d.complex.1" "d.complex.1" 1 4 5 5 48 47 65 21 d.complex.10 ...

How to write a loop in jQuery which waits for each function to complete before continuing the loop

Hi all, Please forgive me if this is an obvious one. I have an unknown amount of elements on a page, which I need to loop through one at a time and do stuff to. However, I need the loop to pause until the functions used on the elements have completed, and then continue on to the next iteration. I tried doing this in a $.each loop, but...

How much can this c/c++ loop be optimized?

I am a newbie on optimization. I have been reading some reference on how to optimize c++ code but I have a hard time applying it to real code. Therefore I just want to gather some real world optimization technique on how to squeeze as much juice from the CPU/Memory as possible from the loop below double sum = 0, *array; array = (double*...

Django Query in a loop fails for no good reason

Hi all, I have this code: msgs = int(post['time_in_weeks']) for i in range(msgs): tip_msg = Tip.objects.get(week_number=i) it always results in an error saying that no values could be found. week_number is an integer field. When I input the value of i directly, the query works. When i print out the value of i I get the expected ...

jQuery - replace loop by className

function loadTextboxes() { var textareas = document.getElementsByTagName('textarea'); for(var i=0; i < textareas.length; i++) { if (textareas.item(i).className == "richtextbox") { richtextbox(textareas.item(i)); } } } //window.attachEvent('onload',loadTextboxes); $(document).ready(fu...

Java: for loop, incompatible types

I'm trying to run this for loop; for (int col= 0; grid[0].length; col++) However every time I try to compile I get an error stating 'incompatible types - found int but expected boolean' I can't work out what I'm doing wrong! ...

MySQL: Loop through databases and run a stored procedure on it

Hi, I'm very new to MySQL and I have a stored procedure that I'd like to add to several legacy databases. I'm using SQLyog and I would like to loop through each database on the connection and if it matches 'application_%' (databases are called application_clientName, there are dozens) to run the stored procedure. A script I can save a...

echo/print issue in php while loop

I need a fix for this.here is just part of my code <?php $number = 30; while($number > 0) { $number--; sleep(30); print "$number . Posted<br>"; } ?> The loop process in the loop is actually much bigger, i just put the important stuff. Anyways as you can see it should print 30 posted (wait 30 seconds) 29 Posted (wait 30 seconds...