loops

PHP: Loop function for every 50 items

Situation: Got 160 ids in array, need to build xml requests, in sets of max 50 and submit each set separately. Problem: How to loop the function and continue with ID 51?function doBatch($ids) Simplified Code: function doBatch($ids) { $start = "<feed>"; foreach($ids as $id) { $add .= '<entry>'$id.'</entry>'; }...

Bash loop ends unexpectedly looping without showing why

I have a bash script with a code like this: echo "EXECUTING TASK 1" sort -r scripts/sh/test-list | while read fn; do sh -vx scripts/sh/test-web-task.sh "$fn" done echo "EXECUTING TASK 2" sort -r scripts/sh/test-unit-list | while read fn; do sh -vx scripts/sh/test-unit-task.sh "$fn" done In test-web-task and test-unit-t...

Batch (xcopy all files to folder) with loop

hello, can anyone help me with loop in batch for windows? i want make script that will allow me to do something like this: 1. copy all folders and files from Drive I: to X:\folder0001; 2. when done display: "Done"; (i ejected cd) 3. "enter" to next copy; 1. copy all folders and files from Drive I: to X:\folder0002; 2. when done display...

jQuery For Loop with Post Not Counting Correctly

So, I have the following line of code, that does a for loop and subjects 12 on every loop. If I alert right before the post, it alerts the numbers as you would expect (72, 60, 48, 36, 24). But, with the alert inside the post it alerts the number 12 five times. Any idea why that is? Any idea where the number 12 is coming from? function l...

Python nested loop with condition

reworked to hopefully make it clearer. my_list = [[1,2],[1,3],[1,3],[1,3]] my_var = 7 My goal is to be able to see if my_var is larger than all of the positions at my_list[0][1] and my_list[1][1] and my_list[2][1] and so on. my_list can vary in length and my_var can also vary so I am thinking a loop is the best bet? *very new to pyt...

scope of pointers to (local) objects declared within a for loop

Dear all, I'm not sure if the snippet of C++ code below is legitimate or not: std::vector<int*> myints; for (int i = 0; i<N; i++) { int j = i; myints.push_back(&j); } for (int i=0; i<myints.size(); i++) cout<<*(myints[i])<<endl; How does the compiler handle this ? I understand the variable j itself goes out of scope when ex...

SQL: How do I loop through the results of a SELECT statement?

How do I loop through the results of a SELECT statement in SQL? My SELECT statement will return just 1 column but n results. I have created a fictional scenario below complete with the Pseudo code of what I'm trying to do. Scenario: Students are registering for their classes. They submit a form with multiple course selections (ie. s...

What's wrong with my for loop?

I am making a game using lite-C (exactly same syntax as C). and I cannot make this loop work. It gives me an error at this line at compilation. for(int i = 0; i < (cantenemigu * 3); i += 3) I have an array with the information of where to create the enemies. the array contains the x,y,z coordinates. cantenemigu is the amount of enemi...

MySQL and PHP - For Each?

Hi all, I have following code: SELECT q21, q21coding AS Description FROM `tresults_acme` WHERE q21 IS NOT NULL AND q21 <> '' ORDER BY q21coding It brings back the following (excerpt): Text Description Lack of up to date equal pay cases&legislation - t... Content needs updating The...

How to show several loops and doing stuff in it in a sequence diagramm?

Hello, I want to show what my UserControl/Control is doing when I plug a list of data in it, what happens when the user press certain keys, selecting text etc... I feel somehow a sequence diagramm is not really suited for showing several loops and doing stuff within the loops. Am I wrong or how can I cope with that case? ...

loops mixed up with MySQL

I'm writing a simple message board where you can reply to any thread and then reply to any reply and so on.... everything works well but is there a simple method to loop the query as this could potentiality go on and on and on $rsql = "SELECT * FROM rotd_mb WHERE reply='N' ORDER BY dateTime DESC"; $result = runSQL($rsql); while ($ro...

rewrite and redirect

hi i just applied a new url structure to my site the links were like this before using rewrite mod /detail.php?id=123 and after /restaurant123.htm but the problem is /detail.php?id=123 still work and i've spent a week to do something to redirect /detail.php?id=123 to /restaurant123.htm without an infinite loop and i searched all over th...

JavaScript: Looping over array

Would it be wrong to conclude that the fastest way to loop over a JavaScript array would be to use the for-in loop? E.g.: for (var index in items) { ... } See http://jsperf.com/loop-test2/2 ...

4D matrix calculation, Matlab coding problem

hey guys, I got some difficulty here. It is purely coding algorithm problem. Okay, the program is shown below: for f=1:(nFrames-1) h=histogram(imgYuv(:,:,1,f)); j=histogram(imgYuv(:,:,1,f+1)); X=abs(h-j)/256; %normalize the difference S=sum(X); end Basically, I want to calculate the difference between two adjacent elem...

Predict the number

I want the user to enter a 4 digit number and the program must tell what that 4 digit number was i.e generate that 4 digit number by Brute force attack.But at the line mentioned below the compiler says invalid indirection.I would also like to have some comments about they way I am implementing it,is it a good practise? #include<stdio.h>...

Efficiency of boolean comparisons? In C.

I'm writing a loop in C, and I am just wondering on how to optimize it a bit. It's not crucial here as I'm just practicing, but for further knowledge, I'd like to know: In a loop, for example the following snippet: int i = 0; while (i < 10) { printf("%d\n", i); i++; } Does the processor check both (i < 10) and (i == 10) for e...

golfscript nested while loops

Are nested while loops broken in golfscript or do I not know how to use them? I want to iterate Q from 5 to 0, and for each iteration, iterate Z from 10 to 0. The single loops work well separately, and they seem self-contained (not relying on the stack between operations): 5:Q; {"Q:"Q+ p Q} { Q 1- :Q; }while 10:Z;{"Z:"Z+ p Z}{Z 1- :...

Access VBA - How would I have a loop in VBA that allows me to loop through control names

So I have like 10 text boxes on a form that are actually used for display not entry. They are are named like txt_001_Name, txt_002_Title, etc..what kind of loop is used for this. I was wondering what kind of VBA would I use to actually loop through the names of the text boxes. So if I was to debug.print it would look like: txt_001_Titl...

Faster to declare variables inside a loop or outside a loop?

Is it faster to declare variables inside a loop or outside a loop? For example: ' Declaration inside of the loop For each item in items Dim newVariable as String = GetAString() Next ' Declaration outside of the loop Dim newVariable as String = String.Empty For each item in items newVariable = GetAString() Next Which one is fa...

Using Applescript loop to recursively apply View options

I'm trying to advance an Applescript to set Finder window views - recursively - as many levels deep as there may be in any given folder. I can achieve the desired results but only in one window/folder; despite hours of searching and experimenting I'm still unable to wrap my noob head around Applescript's seemingly simple syntax (vis a vi...