loops

looping through multiple arrays and inserting into SQL

Hi, I have a form that once submitted some of its result are stored in arrays, example: (The form has multiple lines with the same input names) <select name="product[]"> once submitted goes into $_GET['product'] if I do: // Product ID's foreach($_GET['product'] as $name => $prodvalue) { print "$name : $prodvalue<br>"; } the follo...

PHP - help coding echo statement to create every other line of different background colors

I am creating a table (stats_1) dynamically and would like to have each row of different background color. So far, all the lines have the same background color. I have the following php code that prints echoes out and statements: $keys = array('Col1', 'Col2','Col3','Col4','Col5','Col6','Col7'); echo '<table id="stats_1"><tr>'; ...

Looping for Deep Nested Array

Hi, I am here to ask a nested array question. I have a file say, "content.json" which has javascript variables and json as their values in json there are objects as value and objects as value of each object. I mean there is deep chain to overcome to reach the final value and it is not already decided how many elements at the root are an...

iPhone: Fast enumeration, not fast enough?

I am trying to loop through an NSSet that has about 6500 items in it. I am using: for (id Location in sortedArray) { loc = [sortedArray objectAtIndex:i]; cord = [cord stringByAppendingString:[NSString stringWithFormat:@"%f,%f ",[loc.longitude doubleValue],[loc.latitude doubleValue]]]; i++; } ...

Fatal error from incrementing loop.

Currently, I'm trying to make a function that sorts a vector full of fighters in the function sortFighters in the Fighter.cpp file. It all seems to compile correctly; However, when it does run, I get a fatal error in one of the lines of the aformentioned .cpp file. I know exactly what the problem is, and put a comment there accordingly. ...

a bug related to While and For loops in javascript...!!!

Dear all, I have some trouble as simple as debugging a for loop or a while loop. Do you have any clue? a function that returns data without any iteration works fine but not the loop. <script language = "javascript"> function h(arr) { <![CDATA[ var ref = arr[0]; i = 0 while(i<arr.length){ ...

PHP Retry Script until Success or Error

Hi there, Thank you for taking the time to read this and I will appreciate every single response no mater the quality of content. :) I'm trying to create a php script which retries another php script up to 3 times until an error message is displayed. I'm thinking perhaps this could be done using a php loop? If the code works successful...

Only returning parents in the wordpress loop

I am using a custom post type in my wordpress theme, and I need help with the loop. Here is my code: <?php $loop = new WP_Query( array( 'post_type' => 'magazine', 'posts_per_page' => 10 ) ); ?> <?php while ( $loop->have_posts() ) : $loop->the_post(); ?> <li> <?php the_post_thumbnail( 'magazine' ); ?> ...

Referencing list entries within a for loop without indexes, possible?

A question of particular interest about python for loops. Engineering programs often require values at previous or future indexes, such as: for i in range(0,n): value = 0.3*list[i-1] + 0.5*list[i] + 0.2*list[i+1] etc... However I rather like the nice clean python syntax: for item in list: #Do stuff with item in list or for...

PHP & MS SQL - Foreach Loop?

Hi All, I have a table in my ms sql database and am using PHP. What I am trying to do is: Foreach User in table, get his age and favorite color. And for each entry i want to edit it before it is displayed. For example Each User that is retrieved and displayed on the webpage will be hyperlinked. His/her age will be hyperlinked and the ...

coldfusion threads: looping session variables + sleep

hey guys I'm trying to create a timer which counts the time spent on a page using a thread heres what I have so far: <cfset session.time=0> <cfthread name="timer" action="run"> <cfscript> counter = 0; while (counter <9000) { sleep(1000); session.time++; counter ++; } </cfscript> </cfthread> page 2: <cfoutput>#session...

Can StringTemplate iterate through 'values' in a String?

I have a String made up of several Strings seperated by commas. Using StringTemplate, is there an easy way to write a seperate line for each 'value' in this outer String? For example, I have: String layers = "ADM,NAV"; and I want to output: ADM,Y, NAV,Y, I suspect the template would look (if it's possible) something like this: $...

Best infinite loop.

Possible Duplicate: while (1) Vs. for (;;) Is there a speed difference? Hi, Which is better,faster and more optimized way to implement infinite loop - for(;;) or while(1)? and why? ...

why does i++ and ++i in a for loop behave the same?

Possible Duplicates: Difference between i++ and ++i in a loop? java for loop pre-increment vs post-increment When using the standard for loop, how does the compiler treat the incrementing of the for loop variables? For example, for(int i = 0; i < 5; i++) { System.out.println("i is : " + i); ...

Define dynamic JSON-Array

Hey, i've got a new problem. I know how i have to define a static JSON-Array, but now i must make this dynamic so i could add items with a loop. this is the static version: $json = array(array('field' => 'name', 'value' => $name), array('field' => 'nummer', 'value' => $numbers));...

PHP - when using foreach to loop through array, how can I tell if I'm on the last pair?

I'm trying to 'pretty-print' out an array, using a syntax like: $outString = "["; foreach($arr as $key=>$value) { // Do stuff with the key + value, putting the result in $outString. $outString .= ", "; } $outString .= "]"; However the obvious downside of this method is that it will show a "," at the end of the array print out,...

looping through a rails data object from the controller

I have called a function from a class to find all the items related to a particular ID in a many to many HABTM relationship. Procedures -> Tasks with a join table: procedures_tasks I call the information like @example = Procedure.get_tasks(1,1) I would like to be able to iterate through the data returned so that I can create an i...

Perl: simple foreach on hash hands mixed results?

Possible Duplicate: What decides the order of keys when I print a Perl hash? Say I got a simple script to list the contents of a hash from a book: my %hash = ("a" => 1, "b" => 2, "c" => 3, "d" => 4); for my $i (%hash) { print $i . "\n"; } On one computer it lists: c 3 a 1 b 2 d 4 But on another it has it proper (in or...

Please help me shorten my code..

Hey guys, My question is to shorten repeating the process. Data1=dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\t',[31 1 286 255]); Data2=dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\t',[299 1 554 255]); Data3=dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\t',[567 1 822...

JavaScript loop performance - Why is to decrement the iterator toward 0 faster than incrementing

In his book Even Faster Web Sites Steve Sounders writes that a simple way to improve the performance of a loop is to decrement the iterator toward 0 rather than incrementing toward the total length (actually the chapter was written by Nicholas C. Zakas). This change can result in savings of up to 50% off the original execution time, depe...