loops

XSLT: generate multiple object by incrementing attribute and value

Hi, I have a xml as below that I'd like to copy n times while incrementing one of its element and one of its attribute. XML input: <Person position=1> <name>John</name> <number>1</number> <number>1</number> </Person> and I'd like something like below with the number of increment to be a variable. XML output: <Person position=1> <na...

Is there a way to use a Ruby loop inside of HAML's :javascript region?

Inside of HAML, can we have a loop inside the :javascript region? This will work: - 10.upto(20) do |i| :javascript document.getElementById('aDiv').innerHTML += '#{i}'; and this will not: :javascript - 10.upto(20) do |i| document.getElementById('aDiv').innerHTML += '#{i}'; can the code above also be made to work as well...

Calling multiple functions sequentially with jquery.

I want to loop through an object that contains functions which will execute one after another. My most ideal approach would be to have these chain somehow (ie. func2 waits for func1 and func3 waits for func2) but this needs to happen dynamically and the functions will all have different durations. I'm using jQuery so I thought that per...

loop prematurely quitting

This loop works fine but prematurely quits at times. I set a piece of code in it so that I can view the random number. It only closes prematurely when the random number is equal to the highest numbered question the user inputs (Example...a user wants 10 questions, if the random number is 10 the program quits.) I have no idea why since ...

Calculations coming out to 0.0?

A simple percentage calculation. It wont return a value except 0.0 and I think once or twice it returned 100.0%. Other than that it won't do a thing. I have tried playing with the code in several different ways and it just wont work. for (int loop = 1; loop < loopCount; loop++) { aa = r.nextInt(10+1); ...

How to do it more efficiently?

Let's imagine we should get some data... var data = []; //some code omitted that might fill in the data (though might not) Then we need to do something with the data. And my question is how to do it more effectively. Like so?: if (data.length) { for (var i = 0; i < data.length; i++) { //iterate over the data and do somet...

Python iteration

I'm trying to do a simple script in Python that will print hex values and increment value like this: char = 0 char2 = 0 def doublehex(): global char,char2 for x in range(255): char = char + 1 a = str(chr(char)).encode("hex") for p in range(255): char2 = char2 + 1 b = str(chr(char...

Displaying a single term of a custom taxonomy in Wordpress

How am I able to show a single term of a custom taxonomy in Wordpress? I have a custom taxonomy, which will always have only one term in it, and I want to display it in a custom loop on my home page. I have tried all possible ways, with one (blargh, can't remember which one) I managed to display the term but as a link, which I don't wan...

how to dynamically exit a jquery $.each()??

i have a list of images which i am getting through ajax and then using jquery $.each() i loop through the images and display a image one after the other after an interval of one second. I want the user to be able click on a stop button and so that the user can stop at a particular image if he wants to. So i need to dynamically exit $.ea...

Python - making counters, making loops?

Hi, I am having some trouble with a piece of code below: Input: li is a nested list as below: li = [['>0123456789 mouse gene 1\n', 'ATGTTGGGTT/CTTAGTTG\n', 'ATGGGGTTCCT/A\n'], ['>9876543210 mouse gene 2\n', 'ATTTGGTTTCCT\n', 'ATTCAATTTTAAGGGGGGGG\n']] Using the function below, my desired output is simply the 2nd to the 9th digits ...

javascript function won't stop looping - It's on a netsuite website

I need to change the shipping carrier drop-down and shipping method radio button once via a javascript function, not forever. However, when I use this function, which executes when on the Review and Submit page when the order is < $5, it goes into an endless loop: function setFreeSampShipping(){ var options = document.forms['checkout'...

Images wont show after I've cleared the content

Hey everyone, I'm a newbie using jquery and js either, so maybe thats the reason why i just cant undesrand why my code isn't working. I created this function createList to push image content into div element. (this part works great) So what i want to do is, creating an element witch holds every picture and after i have deleted the cont...

Having a PHP script loop forever doing computing jobs from a queue system.

Currently I have a perl script that runs forever on my server, checking a SQS for data to compute. This script has been running for about 6 months with no problems what so ever. So, now I want to switch over to PHP'S CLI, and have the script loop there forever. Mostly because I'm more familiar with PHP. Basicly, $i="forever"; while($i...

vb.net sqlite how to loop through selected records and pass each record as a parameter to another function

Hi, I have a sqlite table with following fields: Langauge level hours German 2 50 French 3 40 English 1 60 German 1 10 English 2 50 English 3 60 German 1 20 French 2 40 I want to loop through the records based ...

Can I pull the next element from within a Perl foreach loop?

Can I do something like the following in Perl? foreach (@tokens) { if (/foo/){ # simple case, I can act on the current token alone # do something next; } if (/bar/) { # now I need the next token, too # I want to read/consume it, advancing the iterator, so that # the next loop iterat...

Retrieve array key passed on value PHP

I have the following array $group= array( [0] => 'apple', [1] => 'orange', [2] => 'gorilla' ); I run the array group through an for each function and when the loop hits values of gorilla I want it to spit out the index of gorilla foreach ($group as $key) { if ($key == gorilla){ echo //<------ the index of g...

Add a child inside a newly created instance, inside of a loop in AS3

I am trying to create a gallery where each thumb is housed inside of it's own movie clip that will have more data, but it keeps failing because it won't let me refer to the newly created instance of the movie clip. Below is what I am trying to do. var xml:XML; var xmlReq:URLRequest = new URLRequest("xml.xml"); var xmlLoader:URLLoader = ...

input of while loop to come from output of `command`

#I used to have this, but I don't want to write to the disk # pcap="somefile.pcap" tcpdump -n -r $pcap > all.txt while read line; do ARRAY[$c]="$line" c=$((c+1)) done < all.txt The following fails to work. # I would prefer something like... # pcap="somefile.pcap" while read line; do ARRAY[$c]="$line" c=$((c+1)) done ...

Trying to sentinel loop this program.

switch ( choice ) { case '+': System.out.printf( "The answer is: %1$.4f.\n", first + second ); break; case '-': System.out.printf( "The answer is: %1$.4f.\n", first - second ); break; case '*': System.out.printf( "The answer is: %1$.4f.\n", first * second ); ...

Counting entries in a list of dictionaries: for loop vs. list comprehension with map(itemgetter)

In a Python program I'm writing I've compared using a for loop and increment variables versus list comprehension with map(itemgetter) and len() when counting entries in dictionaries which are in a list. It takes the same time using a each method. Am I doing something wrong or is there a better approach? Here is a greatly simplified and ...