loops

WP help need help with loops and custom fields

Basically in the left block (the one w/ red boxes) is a product gallery block where it should spit thumbnails of products (the red boxes). the thumbnail is a "custom field" of a product page, the name of the custom field is "gal_thumb" and is link to it's page. At the right side (the one w/ blue box and some text) is a Services Block....

Performance of find() vs. for loop

I've got a large (4000 values) set of unsorted, normally distributed points. I'm taking each of these data points into bins whose limits are in the BinLimit array. Then I'm tabulating the number of values in each bin. X is the array of raw data, and N is the number of data points. The number of bins desired (TotalBins) is specified by t...

PHP Looping through an array with strings AND an array inside

Hi all, This is a basic looping question but with a twist, so it's likely that i'm missing something easy - apologies in advance... I'm trying to pull the results from an array $testoutput - which is filled with 3 arrays: Running the following code: foreach ($testoutput as $ID => $Array) { echo $Array . "<BR>"; } Returns: ARRAY ...

What does ":" mean in this Java statement?

for (Season time : Season.values() ) system.out.println (time+ "\t" + time.getSpan()); I see an example for enumeration using :. What does this mean? ...

Tell the end of a .each loop in ruby

If i have a loop such as users.each do |u| #some code end Where users is a hash of multiple users. What's the easiest conditional logic to see if you are on the last user in the users hash and only want to execute specific code for that last user so something like users.each do |u| #code for everyone #conditional code for las...

Why is foreach loop Read-Only in C#

Why is foreach loop a read only? I mean you can fetch the data but can't increase++ or decrease--. Any reason behind it? Yes I am a beginner :) Exmaple: int[] myArray={1,2,3}; foreach (int num in myArray) { num+=1; } ...

Performance difference between iterating once and iterating twice?

Consider something like... for (int i = 0; i < test.size(); ++i) { test[i].foo(); test[i].bar(); } Now consider.. for (int i = 0; i < test.size(); ++i) { test[i].foo(); } for (int i = 0; i < test.size(); ++i) { test[i].bar(); } Is there a large difference in time spent between these two? I.e. what is...

How can I use Perl's LWP::UserAgent to fetch the same URL with different query strings?

I have a running LWP::UserAgent that should be applied on following URL: http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=5503 This runs with many many similar targets see the following endings: html?show_school=5503 html?show_school=9002 html?show_school=5512 I want to do this with use LWP::UserAgent: fo...

Python: I am unable to comprehend the concept of a For Loop, apparently.

I've got a list of 400 numbers, and i want to but them in a 20x20 grid using Python. I've made a "2d array" (not really because Python doesn't support them, I've had to use a list of lists.) When i try to loop through and assign each subsequnt item to the next box in the grid, it fails. i end up assinging the last item in the list to ...

Bash For-Loop on Directories

Quick Background: $ ls src file1 file2 dir1 dir2 dir3 Script: #!/bin/bash for i in src/* ; do if [ -d "$i" ]; then echo "$i" fi done Output: src/dir1 src/dir2 src/dir3 However, I want it to read: dir1 dir2 dir3 Now I realize I could sed/awk the output to remove "src/" however I am curious to know if there is a be...

How can I optimise my awful code for finding the highest palindrome of a 3 digit number ?

This is what I have written so far. It compiles, and, as far as I can tell, it should 'work' - if you were to give your computer an infinite amount of time to compute the answer ! I was just wondering if anyone would please be able to give me a way to optimise this so that my program will tell me the highest palindromic number (the sam...

php do something for every record in the database

Hey everyone I have two tables in the database(videos and viewData) . Im trying to build a script that runs for each record in the "videos" table and does something using the "videoID" field for that specific entry in the "videos" table. The does something part would be dumping some data into the viewData table. Would I need to store ...

mysql_query in a while loop

I'm trying to execute I have an html form in a page of this sort : Name: <input type="text" id="namebox" value="" name="fields[]" /> <br /> Position: <input type="text" id="positionbox" value="" name="fields[]" /> <br /> <input type="hidden" name="createcard"> <input type="submit" value="Create"> .. and 3 other fields. I'm passi...

A problem with JavaScript size animation

Hi! I am in the middle of writing a JavaScript library and I have hit a problem, I have a function that resizes elements, that all works good but I also have and animated version that resizes them over a specified time frame. The script seems to freeze when ever it is run and it seems to be down to my while loop, here is my code. // Res...

Help speeding up a loop in R

basically i want to perform diagonal averaging in R. Below is some code adapted from the simsalabim package to do the diagonal averaging. Only this is slow. Any suggestions for vectorizing this instead of using sapply? reconSSA <- function(S,v,group=1){ ### S : matrix ### v : vector N <- length(v) L <- nrow(S) K <- N-L+1 ...

How can I loop through a series of response variables with a specific prefix in PHP?

I'm posting a form to a php script. The form contains a dynamic number of fields named cardObjectX, where X is a counter. Example: cardObject1, cardObject2, and so on. I need to loop through all the cardObject fields in my php script, but because we don't know how many there will be for any given post, we can't hard-code the field names....

Prime test, 2-digit numbers

Hi, I want to print all prime numbers that are 2-digits long. Here is my code: for(int input = 11; input <= 99; input += 2){ for(int x = 2; x < (int)Math.sqrt(input) + 1; x++){ if(input%x != 0){ System.out.println(input); break; }else{ break; ...

VBA While loop using an SQL statement as my While.

Hi there, I'm writing some code behind some spreadsheets and I need to loop through some code, like getting data from a database doing some formulas and moving the data to a new sheet. My code for getting the data from the database is getting all of the values in multiple columns where the data has not been reported and has the same fil...

Python Noob - Silly Question? Works in Python Interpreter, not from CLI...

I am hoping this is a simple stupid noob mistake that can be fixed with the addition of a single line of code somewhere. I'm using pySerial to read in serial data from a USB port and print it out to standard output. I'm running Mac OSX 10.6. I open terminal and type "python", then the following: >>> import serial; >>> ser = serial.Seri...

Perl: Running a "Daemon" and printing

I am running a script that runs 24/7. It just loops through over and over, very simple: while ($daemon) { sleep 60; chomp(my $currentDate = `date +%c`); print LOG "-- Running trigger: $currentDate --\n"; system("$triggerCmd >> $daemonLog"); print LOG "-- Completed trigger test. --\n\n"; } It works fine. ...