loops

writing the outcome of a nested loop to a vector object in R

Dear Stackers, I have the following data read into R as a data frame named "data_old": yes year month 1 15 2004 5 2 9 2005 6 3 15 2006 3 4 12 2004 5 5 14 2005 1 6 15 2006 7 . . ... . . . ... . I have written a small loop which goes through the data and sums up the yes variable for each ...

Loop Limit in C/C++

Is there a limit to how many times a loop can run in C? void main() { int T,N,x,X,i; x=0; scanf("%d", while(T>0) { T--; scanf("%d", X=0; while(N>0) { N--; scanf("%d", if(x>X){X=x;} } printf("Case: %d",x); } } T has a ra...

For C Language: How to do you Display a growing Series of Numbers using the For Loop per line?

How do you make C use the For Loop Statement and generate this: 1 12 123 1234 12345 123456 1234567 12345678 I know this requires that the value "1" to be continuously be multiplied with "10" and added with "1". ...

Efficiency of Preg_replace

Executive Summary: preg_replace() ran faster than string comparisons. Why? Shouldn't regular expressions be slower? In a recent question about detecting any of an array of disallowed substrings within a given input, I suggested comparing the result of a preg_replace() call to the original input, since preg_replace() can take an array...

Binding click event handlers in a loop causing problems in jQuery

I am trying to run the following code: I pass parameter to a function, but it always has the value of the last object run through the loop. I read some articles about it on stackoverflow, but I couldn't find out how to make it run in my solution. The object is a JSON object returned from the server. All it's values are correct. for(v...

php foreach: put each of the loop result in one variable

Hi, I think this is probably a very simple but I can get my head around! How can I put each of the loop result in one variable only? for instance, $employeeAges; $employeeAges["Lisa"] = "28"; $employeeAges["Jack"] = "16"; $employeeAges["Ryan"] = "35"; $employeeAges["Rachel"] = "46"; $employeeAges["Grace"] = "34"; foreach( $employeeAge...

What is the difference between infinite while loops and for loops?

I see the different conventions used in many books I had read, where you would create infinite loops with either loop structure such as: while() foo(); for(;;) foo(); But really, what are the differences I should know about? which one is better? ...

How can I output a calculated value using .detect in Ruby on Rails? (or alternative to .detect)

I currently have the following code: events.detect do |event| #detect does the block until the statement goes false self.event_status(event) == "no status" end What this does is output the instance of event (where events is a string of different Models that all collectively call Events) when the event_status method outputs a "no ...

Insert 52 weeks for each year in MySQL (PHP script)

Hi, I want in a table called week_year with following schema: Week_year = {id, week, year} To insert the weeks for each year, such that, for 2001 there is week 1, week 2, week 3, … , week 52, and then start over for year 2002 up until the year 2009. I’ve tried different PHP scripts but can’t seem to be getting it right. I’ve tried ...

Wordpress & Fancybox - Loop issue? - fancybox keeps reloading page

Problem page: www.kendraschaefer.com/mandapop (problem with images in thin middle column) Hi, I'm working on a new Wordpress template, and I've run into an issue with Fancybox. I'm trying to get the pictures in the thin middle column of the page above to, when clicked on, pop up in fancybox with attached post data. It's mostly workin...

nested SQL Stored proc while not looping

I am trying to generate a set of rows for a matrix but the @xcolcount only does on loop staying at zero while the inner loop does what it needs to: Declare @xColCount int Declare @yRowCount int set @xColCount = 0 set @yRowCount = 0 WHILE (@xColCount < @widthCol) BEGIN WHILE (@yRowCount < @heightRow) BEGIN -- do the i...

WordPress loop display 1 post for each author

I have several authors on a blog, and on the home page (index.php) I want to query the posts so that it only shows the latest post from each author. So say I have 5 authors it will show 5 posts each being the most recent for each author. Any ideas on how to do this? I don't want to create separate loops for each author, it has to be aut...

postfix and prefix increment operator in a for loop

Possible Duplicate: Difference between i++ and ++i in a loop? Can anyone explain what's the difference between those: for(unsigned col = 0; col < n; ++col, num_to_fill >>= 1U) { for(unsigned row = num_to_fill; row < (1U << n); row += (num_to_fill * 2)) { std::fill_n(&output[col][row], num_to_fill, 1); } }...

How can I pause/restart a loop in objective-c

Would like to execute some code in a loop, but I want to pause it while a uiscrollview is scrolling. I've created a BOOL named isScrolling that is set to "YES" in the scrollViewDidScroll method and is set to "NO" in the scrollViewDidEndDecelerating method. I'd like to put the loop in the scrollViewDidEndDecelerating method, but have i...

Need help with loops

Hi, I need a loop in this pattern. I need an infinite loop producing number that start with 1. 1,10,11,12..19,100,101,102..199,1000,1001....... ...

A simple controller loop (including open flash chart)

I have a simple problem regarding a loop in a Rails controller. Here's the original sample code, the purpose of which is to specify the data to be used in an open flash chart (pie chart). #controller data_1 = [ OFC2::PieValue.new(:value => 20, :label => 'GroupA', :font_size => 15), OFC2::PieValue.new(:value => 30, :label => 'Grou...

PHP: count how many times a number appears in an array?

I'm running a loop basically that will make an array that contains a million numbers between 1 and 10, how do I iterate through it and count how many of each there are? Like: 1 - 201491 times 2 - 23091 times ...

Problems removing elements from a list when iterating through the list

I have a loop that iterates through elements in a list. I am required to remove elements from this list within the loop based on certain conditions. When I try to do this in C#, I get an exception. apparently, it is not allowed to remove elements from the list which is being iterated through. The problem was observed with a foreach loop....

Javascript data structure for fast lookup and ordered looping?

Hi, is there a data structure or a pattern in Javascript that can be used for both fast lookup (by key, as with associative arrays) and for ordered looping? Right, now I am using object literals to store my data but I just disovered that Chrome does not maintain the order when looping over the property names. Is there a common way to ...

Finding the index of a list in a loop.

Hello all. I have a simple question. If I have a for loop in python as follows: for name in nameList: How do I know what the index is for the element name? I know I can some something like: i = 0 for name in nameList: i= i + 1 if name == "something": nameList[i] = "something else" I just feel there should be a more ...