loops

C# Loop limited to 50 passes

How do I limit the loop below to 50 so it stops when it reaches the 51st item? foreach (ListViewItem lvi in listView.Items) { } Thanks ...

PHP: array modifications that persist beyond the scope of a foreach loop

How can I add a new key/value pair to an existing array inside of nested foreach loops and have that pair persist outside the scope of the loops? <?PHP include('magpierss/rss_fetch.inc'); /* one, two, skip a few... $urls is an associative array with database indices as keys and URLs as values ...

How do i exit a List<string>.ForEach loop when using an anonymous delegate?

In a normal loop you can break out of a loop using break. Can the same be done using an anonymous delegate? Example inputString and result are both declared outside the delegate. blackList.ForEach(new Action<string>( delegate(string item) { if(inputString.Contains(item)==true) { result = true; ...

How to dynamically set an increasing value per row in MySQL

I am creating a web application that acts as a priority list, allowing a user to re-arrange a set of items in a list and storing that arrangement in a MySQL database via a PHP backend. At the moment, when the user has finished arranging their items and saves the configuration, I am calling a seperate UPDATE statement for every row, plug...

SQL Looping

I'm building this report in a system for a Billboard company. They have a table that stores all their billboards, and among other data, billboards have a Start Date and a Finish Date (both can be null). If for some reason a billboard has to stop beeing used, they set a finish date and it will become unnavaiable to be used after that date...

Mathematical problem: loop or recursive

I´m trying to break a number into an array of numbers (in php) in the way that for example: 25 becomes (16, 8, 1) 8 becomes (8) 11 becomes (8, 2, 1) I don´t know what the correct term is, but I think the idea is clear. My solution with a loop is pretty straightforward: $number = rand(0, 128); $number_array_loop = array();...

What is wrong with my nested loops in Python?

How do I make nested loops in Python (version 3.0)? I am trying to get the following loops to show me the products of two numbers: def PrintProductsBelowNumber(number): number1 = 1 number2 = 1 while number1 <= number: while number2 <= number: print(number1, "*", number2, "=", number1 * number2) ...

FileInfo[] array, want to add it to a queue so each file is processes only once and removed

Hi, I have an array of files in the object FileInfo[]. In my service, I am currently looping through the files and processing them. I want to loop through the files, and remove them from the collection as they are processed. I think a queue is ideal for this, but how can I loop through a queue collection? (never used a queue in C# ...

Dividing loop iterations among threads

I recently wrote a small number-crunching program that basically loops over an N-dimensional grid and performs some calculation at each point. for (int i1 = 0; i1 < N; i1++) for (int i2 = 0; i2 < N; i2++) for (int i3 = 0; i3 < N; i3++) for (int i4 = 0; i4 < N; i4++) histogram[bin_index(i1, i2, i3, i4)] += 1; // see b...

What is the fastest way to copy my array?

I'm doing some Wave file handling and have them read from disk into an array of bytes. I want to quickly copy portions from this byte array into another buffer for intermediate processing. Currently I use something like this: float[] fin; byte[] buf; //fill buf code omitted for(int i=offset; i < size; i++){ fin[i-offset] = (float) bu...

How do I read two items at a time in a Perl foreach loop?

What I'm looking for is something like: @list = qw(1 2 3 4 5 6) foreach (@list) { #perl magic goes here print "i: $i, j:$j\n"; } returns: i:1, j:2 i:3, j:4 i:5, j:6 In response to a very good suggestion below, I need to specify that this script will run on someone else's build server, and I'm not allowed to use any modules from...

What is the best method for creating your own Wordpress loops?

There seem to be three main ways to output content from Wordpress using its built-in functions, with WP_Query being the recommended one: WP_Query query_posts get_posts What are the differences between them? (I understand that WP_Query is the class, and the other two are methods). What is the cleanest way to have multiple loops on th...

Endless background-color animation in jQuery, how?

Hi, I'm working on a web form where I wish to (after form submission) highlight those input fields that weren't entered correctly. The highlight effect I wish to create is an endlessly looping animation between background-color: #fcc; and #fff; in the faulty input fields, using jQuery. When one of those fields gain focus, I wish to stop...

How can I stop a Java while loop from eating >50% of my CPU!?

Okay, I tested this on an empty program, and just having a while(true){} running gave me >50% on my CPU. I have a game I'm working on that uses a while loop as it's main loop, and it's CPU is at 100 all the time. How can I get Java to repeat something over and over without eating up >50% of my CPU just to do the repeating? ...

Persisting variable value in Python

for i in range(0,3): j = 0 print 'incrementing ' j += 1 print j prints incrementing 1 incrementing 1 incrementing 1 How can I persist the value of 'j' so that it prints: 1 2 3 ...

Can you 'exit' a loop in PHP?

I have a loop that is doing some error checking in my PHP code. Originally it looked something like this foreach($results as $result) { if (!$condition) { $halt = true; ErrorHandler::addErrorToStack('Unexpected result.'); } doSomething(); } if (!$halt) { // do what I want cos I know there was no error ...

Automatically refactor a loop into a recursive method?

Do you know a tool that automatically refactors a method with a single loop into a recursive method, preferably in Java? This is for teaching purposes. ...

C++ dll Loop Problem

Hi there. Im having a problem with a loop inside a C++ dll being called from VB. I want this loop to update a global variable, but when I call the function the variable does not update the first time round, but does so every subsequent time. This is how I am trying to update the variable. else { ::nScore = nHighest; if (nScor...

Which is better practice - for loop with break or conditional loop?

I'm just curious what peoples' thoughts are on this topic. Let's say I have an Array of Objects, and I want to loop through them to see if the Objects contain certain values, and if so, I want to stop the loop. Which is better practice - a for loop with a break, or a conditional loop? The pseudo-code in the example I have provided is fo...

how to write a loop in Windbg like this?

Hello everyone, I have a type called Foo and it has a field called length. I want to write a single loop statement in Windbg which will dump length field of all object instances of type Foo in managed heap? thanks in advance, George ...