loops

PHP: foreach variable assignment and referencing: how-to?

I have an array: $aPerfparse as 2-dimensional array where index ranges from 0 to n-1, * aPerfparse[index]['label'] - label of the perfdata * ['value'] - actual perfdata * ['uom'] - unit of measurement (might be NULL) Need to iterate through each item and set each ...

How would you keep a Math.random() in javascript from picking the same numbers multiple times?

I have an array var words = []//lots of different words in it. I have a Math.floor(Math.random()*words.length) that chooses a random word from the array. This is run in a loop that runs for a random number of times (between 2 and 200 times). I would like to make sure that the random numbers do not get chosen more than once during the tim...

For Loop to populate Array?

In the ImageAdapter class of this tutorial, http://developer.android.com/resources/tutorials/views/hello-gridview.html I would like to create and populate an array using a for loop. But it seems no matter where I place it, it causes an error. For example, under private Context mContext; I put in the following and it causes an error. I ...

Is an if with a continue a good pattern to prevent excessive nesting while iterating over properties in Javascript?

I normally use this pattern to iterate over object properties: for(var property in object) { if(object.hasOwnProperty(property)) { ... } } I don't like this excessive indentation and recently it was pointed out to me that I could get rid of it by doing this: for(var property in object) { if(!object.hasOwnProperty(prope...

How to make a batch work with long path names and spaces for a For Loop with subdirectories ?

How to make a batch work with long path names and spaces for a For Loop with sub-directories ? paths to files will be over 200 or 300 letters. What i m trying to do is to bulk convert multiple files with a program that let me insert the input file directory path+name and the output file directory path+name in a .INI that comes with the...

Loop Trick - How to show one attribute if... ?

Hi! I'm looking for a function we can use in a loop to do this: <% for rink in @rinks_in_region %> <%= rink.city #Show Only if city (n-1) != n %> <%= link_to_rink(rink.name+" Ice Rink",rink) %> <br> <% end -%> Basically just show the city only if it's different than the previous one. Make sense? Thanks for your help! ...

Data deduplificaton

The code below explains best what I'm trying to accomplish. I know that I can use a cursor or other looping routine to loop through the records to find the duplicates and create my notes records based on what is found. I'm trying to avoid that, unless there's no better option. DROP TABLE #orig DROP TABLE #parts DROP TABLE #part_notes ...

repeat an image when scrolling on iphone

Hi, i've got an UIImageView, now i want to repeat this image, that it always shows up again when scrolling left or right. Little Example: is this possible? it should feel like an infinite loop ...

Close a series of views in a for-loop [iPhone]

I need to close a series of views and don't wont to write code for closing them one by one. Here's a sample code to illustrate what I mean: //This is the method for placing the views. It's called at different times at runtime: - (void)addNotePic:(int)number { int indexNumber = ((110*number) + 10); UIImage *image = [UIImage imageNamed...

How to output permalink for term on WordPress posts in loop?

I have a series of posts within a custom post type which are all have a term within the taxonomy "collection." Each post is associated with no more than one term within the "collection" taxonomy. I want to create a link under each post that says something like "More in this Collection," how can I dynamically create a link to the term tha...

Looping through Elements

Hey guys, I want to make a function loop over all elements that have the class of ".block-header-tabs" and do the following: $(function(){ function cssTabs(){ var firstTab = $(".block-header-tabs").find("a:first"); var firstBlock = $(".block-header-tabs").find("a:first").attr('href'); $(firstBlock).parent().css({position: "relative"})...

What loop to use for an iteration that might be interrupted before the end?

I have a range of memory to parse. If I find a certain sequence of bytes before the end, I interrupt the iteration. I wonder which loop I should prefer here: while(i < end && !sequenceFound ) { // parse i++; } Or for( i; i < end && !sequenceFound; i++ ) { // parse } This is used in a method of a class that derives from ...

Java: For loop and If algorithm

Hello, I've this question from an assignment to create a Store which rent out books, using a Store.java and Book.java. I've finished this assignment, but I'm curious for better algorithm to a specific part. -- Book.java public class Book { private String name; Book(String name) this.name = name; public String g...

Turing complete SQL lib?

I'll rephrase this. How do i execute a mysql query were i can pass an array in instead of write my own semi complex loop generating a very long sql query. I'd like to select docs.id where the doc has each of the tags in a string list. Additional note is doc_tag has id, docid, tagid and tag_name has id, tagname. This probably makes no...

Create a random token, check for a duplicate.

I have a php script that makes a random token (A-Z, a-z, 0-9): function token($length) { $characters = array( "A","B","C","D","E","F","G","H","J","K","L","M", "N","P","Q","R","S","T","U","V","W","X","Y","Z", "a","b","c","d","e","f","g","h","i","j","k","m", "n","o","p","q","r","s","t","u","v","w","x","y","z", ...

How do you do nested iterators in groovy?

Does groovy support any kind of nested iterator notation? In the example below, I want to somehow get the projectName value, that came from the outer iterator, into my inner iterator. Is this possible without storing in a variable? In my example I get a runtuime error that "project" is not found it.myprojects.project.each{ println...

Java - Clip and Looping Sound

I finally got my sound clip to work in my java application. This is picky, but there's a minor pause between each sound loop. Is there any way to "merge" the two loops slightly so the sound seems continuous? ...

How to exit the loop with the number 0? but now i have other problems

package hw3; public class Main { public static void main(String[] args) { final int NumberOfElements = 1000; int[] num = new int[NumberOfElements]; int var = 0; //create input java.util.Scanner input = new java.util.Scanner(System.in); for (int i = 0; i < NumberOfElements; i++) { ...

For and While loops: differences, question, and reasons.

Hi there. I'm trying to figure out some answers to some questions and some difference between While and For loops in C++ and also the reasons? Here's what I've come up with so far. According to http://www.cplusplus.com/doc/tutorial/control/ While is: while (expression) statement and For is: for (initialization; condition; increase) sta...

[R] -- How to start a loop with a first guess?

This is comp sci 101 stuff, but I couldn't find an answer applicable to R (or matlab). I have a for loop that I want to initialize with a first guess (all zeros here, but maybe something else later), but I want to keep updating with each iteration. What I have below works, but it kind of clunky and embarrassing. I would like to avoid t...