loops

Wordpress loop > unique loop renders slightly wrong results...

A few things to understand before my question will make sense: I use a hidden category called 'Unique' to specify if the post will use the single.php or a special one used for the unique ones. I want the index to act as a single: showing only one post, displaying next/prev post links, and comments also. I need the index.php to say if t...

Javascript: Assign dynamically produced values to new array

I'm looping through 3 arrays, finding 'actionTimings' in each array and adding up the actionTimings values (values are all numbers). How would I assign the 3 values I obtain to a new array? Here's what I have so far... $.each(dinnerComponents, function(intIndex, component) { totalCookTime = 0; for ( var i = 0; i < component.actionTimi...

Looping a fixed size array without defining its size in C

Some example code to start the question: #define FOO_COUNT 5 static const char *foo[] = { "123", "456", "789", "987", "654" }; The way this would normally be iterated over, as for one example, is the following: int i = FOO_COUNT; while (--i >= 0) { printf("%s\n", foo[i]); Is there anyway to d...

Looping a statically allocated array, outside of c99 mode?

This is in reference to a solution posted on: http://stackoverflow.com/questions/1969588/looping-a-fixed-size-array-without-defining-its-size-in-c Here's my sample code: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { static const char *foo[] = { "this is a test", "hello world", ...

Nokogiri screen-scrapes a large set of data. How do I save all of the data in Rails?

The following code screen-scrapes fishersci.com for 3 pieces of information: The product name, The product URL and the catalog number and saves the data into 3 table items rec_item, rec_url and rec_cat respectively. # lib/tasks/inventory_courses_new_item.rake task :fetch_new_courses => :environment do require 'nokogiri' require 'o...

Subset Sum TI Basic Programming

I'm trying to program my TI-83 to do a subset sum search. So, given a list of length N, I want to find all lists of given length L, that sum to a given value V. This is a little bit different than the regular subset sum problem because I am only searching for subsets of given lengths, not all lengths, and recursion is not necessarily th...

Do I need to have meaningful names for loop control variables?

Code Complete book suggested, it is a good practice to use meaningful names for loop control variables. For example: for(int month=0; month < MONTHS_PER_YEAR; month++){ // processing } Instead of single letters for example for(int i=0; i < MONTHS_PER_YEAR; i++){ // processing } I follow this practice and use meanin...

XAudio2, starting/stopping loops?

How can I start/stop audio looping in IXAudio2SourceVoice? Basically it has a start/stop which starts and pauses the audio execution as well as an ExitLoop() function which stpos the audio once it has finished playing. What I'd like to do is call 'ExitLoop()' then at a later time restart the looping process. How can I do this? ...

Bash combine two arrays

I have the following situation, two arrays, let's call them A( 0 1 ) and B ( 1 2 ), i need to combine them in a new array C ( 0:1 0:2 1:1 1:2 ), the latest bit i've come up with is this loop: for ((z = 0; z <= ${#A[@]}; z++)) do for ((y = 0; y <= ${#B[@]}; y++)) do C[$y + $z]="$...

Get json values...

Hi, I have search and search the web and also on here.. for loops and all sorts for ways to access a json object like so: [ { name: "tom", text: "tasty" }, { name: "tom", text: "tasty" }, { name: "tom", text: "tasty" }, { name: "tom", text: "tasty" }, { name: "tom", text: "tasty" } ] I want too loop through them an...

Auto incrementing number in PHP foreach loop

This is the beginning of a php for loop. I would like to edit it so that 'INSERT NUMBER HERE' gets replaced with an incrementing number. Ie. first loop it would be 1, then 2, then 3 etc. <?php foreach ($_productCollection as $_product): ?> <div style="float: left; font-size: 120px;height:50px;padding-top:50px; color:#ccc">INSERT N...

Problem with for loop iterations over data from a queue

I'm having a problem reading and processing data from my server. I've spent hours debugging this and it seems as though the problem has nothing to do with the server but is really just an issue with one of my for loops. Its difficult to explain this without actually seeing the data from the server, but I'll do my best to explain this. B...

While(1) in constructor or using threads?

Is it recommed to put a while loop, which never ends in a constructor? Or should I use threads to get the same result? Is it good when a constructor never terminates? Or is it more secure to avoid segmentation faults? Hope you understand my bad English.. ...

DOMDocument::load in PHP 5

Hello all, I open a 10MB+ XML file several times in my script in different functions: $dom = DOMDocument::load( $file ) or die('couldnt open'); 1) Is the above the old style of loading a document? I am using PHP 5. Oppening it statically? 2) Do I need to close the loading of the XML file, if possible? I suspect its caus...

Alternating Designs For Loop Results

I am looking to create alternating designs for the content of each post returned in my loop. In short I want the first post to display left align, next right align, and so on. I have not been able to find a way to do this. Any ideas? ...

How to iterate through set of custom control objects in WPF?

In a window of my WPF application I have a number of objects which dirived from a custom control: ... <MyNamespace:MyCustControl x:Name="x4y3" /> <MyNamespace:MyCustControl x:Name="x4y4" /> <MyNamespace:MyCustControl x:Name="x4y5" /> <MyNamespace:MyCustControl x:Name="x4y6" /> <MyNamespace:MyCustControl x:Name="x4y7" /> ... In my code...

Multithreading python application hangs while running its threads.

I am trying to create a MainObject which is availible as a DBus service. This MainObject should always stay responsive to other objects/processes and for this non-blocking even while processing its items. for that reason items are processed in a seperate thread one after another (queue-style). You can add items to the MainObject via DBus...

PHP - For loop only returns last variable in array

I have a strange problem where a for loop in PHP only returns the last item in my array. The array is created with SimpleXML from an XML file. The code should return this: <tags><tag value="Tag1" /><tag value="Tag2" /><tag value="Tag3" /></tags> But instead I just get: <tags><tag value="Tag3" /></tags> So it ignores all but the l...

How do I limit the number of elements iterated over in a foreach loop?

I have the following code foreach (var rssItem in rss.Channel.Items) { // ... } But only want 6 items not all items, how can I do it in C#? ...

PHP read sub-directories and loop through files how to ?

I need to create a loop through all files in subdirectories. Can you please help me struct my code like this: $main = "MainDirectory"; loop through sub-directories { loop through filels in each sub-directory { do something with each file } }; Can you help, plz? ...