loops

How to copy a variable in JavaScript?

I have this JavaScript code: for (var idx in data) { var row = $("<tr></tr>"); row.click(function() { alert(idx); }); table.append(row); } So I'm looking through an array, dynamically creating rows (the part where I create the cells is omitted as it's not important). Important is that I create a new function which encloses...

java: looping on the two boolean values (false, true)

This is a stylistic question. I want to loop twice with a variable on which is set to false, then to true. Which of these is clearer: A) for (final boolean on : new boolean[] { false, true} ) { doStuffBasedOnABooleanFlag(on); } B) for (int i = 0; i < 2; ++i) { final boolean on = (i == 1); doStuffBasedOnABooleanFlag(on); }...

How to create a dynamic object in a loop?

Basically I want to create one large object of many object in JavaScript. Something like: var objects = {} for (x) objects.x = {name: etc} Any ideas? ...

Indexing my while loop with count parameter in an array

My function takes an array of ifstream ofjects and the number of ifstream objects as seen below: void MergeAndDisplay(ifstream files[], size_t count) My problem is I want to use a while loop to read from the file(s) as long as one of them is open. When I get to eof, I close the file. So I thought I could do something like int fileN...

unreachable statement

I have loop designed to validate the user input on a question, it was working fine until I added this; if (userInput.charAt(0) > NUMCOLS && userInput.charAt(0) < 0); { System.out.println("Error, " + userInput + " is an invalid move."); continue; } before this if (userInput.charA...

Loop Reversal in C# Speeds Up app

We are working on a video processing application using EmguCV and recently had to do some pixel level operation. I initially wrote the loops to go across all the pixels in the image as follows: for (int j = 0; j < Img.Width; j++ ) { for (int i = 0; i < Img.Height; i++) { // Pixel operation code } } The time to exec...

Using wp_query to pull content from a specific post using either title or id

I am trying to pull excerpts and custom fields from specific posts, I have tried using post titles and post id but I am only succeeding in pulling every single post using this query. For example I have this code trying to pull just the title for the post with id 182 <?php $map = new WP_Query(); $map->query('post_id=182'); ?> <?php while...

How do I append a variable to another variable in JavaScript?

I am running a loop, and I am trying to create a variable each time the loop runs with the number of the counter appended to the end of the variable name. Here's my code: var counter = 1; while(counter < 4) { var name+counter = 5; counter++; } So after the loop runs there should be 3 variables named name1, name2, and name3. How c...

Making multiple objects in a for-loop

I have code in Java that should make multiple objects within a for-loop, then add each object into an array. However, the code just copies the same (which is the last in the for-loop) object into each index i in the array once the loop ends. How can I correct this to have each separate object in its correct index in the array? I can po...

Basic syntax for an animation loop?

I know that jQuery, for example, can do animation of sorts. I also know that at the very core of the animation, there must me some sort of loop doing the animation. What is an example of such a loop? A complete answer should ideally answer the following questions: What is a basic syntax for an effective animation recursion that can ...

read() on socket issue

Hi, When I try to do a read() on a socket, it works perfectly fine. But, when I put the same thing in a while loop and try to read into a buffer, it stalls my server. Can anyone suggest a solution? Update: Thanks for the responses. I was so much into the issue that I assumed everyone else in the world knew what I'm speaking about. Sor...

Script stops while waiting for user input from STDIN.gets

I'm trying to do something like this, where I have two loops going in seperate threads. The problem I am having is that in the main thread, when I use gets and the script is waiting for user input, the other thread is stopped to wait as well. class Server def initialize() @server = TCPServer.new(8080) run end ...

Time based VBA script for exercises

I have an excel spreadsheet with two columns, one with a list of exercises (33 of them) and a number of reps for each. What I really want is a program that picks a random exercise, displays it with it's number of reps, and has a button that says something like "Done?" When you click it, I want a timer that counts down 20 minutes, picks a...

C# looping through an array

I am looping through an array of strings, such as (1/12/1992 apple truck 12/10/10 orange bicycle). The array's length will always be divisible by 3. I need to loop through the array and grab the first 3 items (I'm going to insert them into a DB) and then grab the next 3 and so on and so forth until all of them have been gone through. //...

Java for each vs regular for -- are they equivalent?

Are these two constructs equivalent? char[] arr = new char[5]; for (char x : arr) { // code goes here } Compared to: char[] arr = new char[5]; for (int i = 0; i < arr.length; i++) { char x = arr[i]; // code goes here } That is, if I put exactly the same code in the body of both loops ...

Can we run two simultaneous non-nested loops in Perl?

Part of my code goes like this: while(1){ my $winmm = new Win32::MediaPlayer; $winmm->load('1.mp3'); $winmm->play; $winmm->volume(100); Do Some Stuff; last if some condition is met; } Problem is: I want the music to be always on when I'm in the Do Some Stuff stage in the while loop. But the lengt...

Python: For loop problem

I have a simple for loop problem, when i run the code below it prints out series of 'blue green' sequences then a series of 'green' sequences. I want the output to be; if row[4] is equal to 1 to print blue else print green. for row in rows: for i in `row[4]`: if i ==`1`: print 'blue ' el...

Python for loop question

I was wondering how to achieve the following in python: for( int i = 0; cond...; i++) if cond... i++; //to skip an run-through I tried this with no luck. for i in range(whatever): if cond... : i += 1 ...

PHP loop hanging/interspersed/threaded through HTML

I can't figure out how to say what I'm talking about which is a big part of why I'm stuck. In PHP I often see code like this html <?php language construct that uses brackets { some code; ?> more html <?php some more code; } ?> rest of html Is there any name for this? Having seen this lead me to try it out so here ...

how to add (for loop) inside jquery data:

Hi, I have this code to update users data, but I can't write the for loop inside jquery data!! Is there any way to modify the follwing wrong code to be correctly function DisactiveUser() { var num_checkboxes = document.forms[0].elements.length-1; $.ajax({ type: "POST", url: "submit/php/users.php?do=disactive", da...