loops

Why doesn't this for loop execute?

I have a picker view controller to select a chemical source and possibly a concentration. If the source doesn't have concentrations, it just presents a single picker. It gets populated by an NSDictionary with source type names as keys and a custom model object I made called Chemical that has four properties, two NSString, one float and...

how do i fill the entries of this matrix in R?

Given: h_i=t_(i+1)-t_i for i=1,...,n-1 where n is a positive integer. The matrix Q is an n by (n-2) matrix with entries q_(i,j) with i=1,...,n and j=2,...n-1 given by: q_(j-1,j)=1/h_(j-1) q_(j,j)=-(1/h_(j-1)+1/h_j) q_(j+1,j)=1/h_j q_(i,j)=0 for |i-j|>=2 I want to get a matrix Q. How do i write a program for this matrix in R? Many t...

Matlab Problem: If i have a set of matrix and would like to compare any values in the matrix with a number then replace it with 1 or0.

Hi all, I am really new with matlab and would like some helps with matlab.. Here is the problem: Say if i have a 256 by 256 matrix. I would like to replace any values that are 'greater' or 'equal' to 10 with 'one' and name the rest as 'zero' i.e. (values <10).. How can I do it?? For example, 2 3 6 15 24 32 1 7 39 10.... 1 5 7 11 19...

How do I write this array in simple method??

I do have a function which do calculations a lot. $arrleft and $arrright are two different arrays. what I am doing here is I am combining two to produce together output for my current application. what I done is a simple method and it eats lots of space and time. what I want is if any one can make this code to a couple of lines shorter...

How to loop over a Class attributes in Java?

Hello everybody, How can I loop over a class attributes in java dynamically. For eg : public class MyClass { private type1 att1; private type2 att2; ... public void function() { for(var in MyClass.Attributes) { System.out.println(var.class); } } } is this possible in Java? ...

In C++ why can't I write a for() loop like this: for( int i = 1, double i2 = 0; .....

or, "Declaring multiple variables in a for loop ist verboten" ?! My original code was for( int i = 1, int i2 = 1; i2 < mid; i++, i2 = i * i ) { I wanted to loop through the first so-many squares, and wanted both the number and its square, and the stop condition depended on the square. This code seems to be the cleanest ...

Loop in MySql, or alternative?

I have a MySql db with innoDB tables. Very simplified this is how two tables are layed out: Table A: controlID(PK) controlText Table B: controlOptionID(pk) controlID(FK to table A) controlOptionType controlOptionValue So many controlOptions(table B) can reference one control(giving that control m...

32x32 Multiply and add optimization

Hi, I'm working on optimizing an application . I found that i need to optimize an inner loop for improved performance. rgiFilter is a 16 bit arrary. for (i = 0; i < iLen; i++) { iPredErr = (I32)*rgiResidue; rgiFilter = rgiFilterBuf; rgiPrevVal = rgiPrevValRdBuf + iRecent; rgiUpdate = rgiUpdateRdBuf + iRecent; iPre...

How to initialize several variables in a for (;;) loop in C?

I thought one could initialize several variables in a for loop: for (int i = 0, char* ptr = bam; i < 10; i++) { ... } But I just found out that this is not possible, gcc gives the following error: error: expected unqualified-id before 'char' Is it really true that you can't initialize variables of different types in a for loop? ...

Mixing Objective C and C in switch statement trying to add a subview iphone SDK

I'm experiencing a weird problem. I have a for loop, inside the loop there is a switch statement. The counter in the for loop is a pointer that points to the beginning of a primitive array, it increments itself till it finds a "terminator number". The array pointed is used to build a view, each elements represent a subview to put in the ...

'if' inside 'while' statement in php

I have this bit of code which loops through an array and echos out the result to the page thus: while($row = mysqli_fetch_array($result)) { echo '<tr><td><a target="_blank" href="' . $row['url'] . '">' . $row['name'] . '</a></td>' . '<td>' . $row['provider'] . '</td>' . '<td>' . $row['media'] . "</td></tr><br />\n"; } ...

Should I bring temporary variable declarations out of loops in C and C++?

Here is what I mean, suppose I have code like: for (int i = 0; i < 1000; i++) { char* ptr = something; /* ... use ptr here */ } It seems that char* ptr gets allocated every time in the loop, making it ineffective? Is it more effective to write this? char* ptr = something; for (int i = 0; i < 1000; i++) { /* ....

Looping through files with perl

Okay I have 2 files. One file is data that is updated every 10 minutes while the second is data that was previously used. What I am trying to do is take one line from the new file and loop through each line of the second file and see if it matches one. If it does I dont want to use it, but if there is no match than I want to add it to a ...

Iterating variables to change its features in Python

I assigned values with setattr() function in a loop: for i in range(30): for j in range(6): setattr(self, "e"+str(i)+str(j), Entry(self.top)) , then I want to apply .grid() func. to all these variables with a loop. For example, self.e00.grid(row= 0, column= 0) How can I do that? ...

Iterating through columns in VBA (Excel)

When I typed that title, I came across many help topics and looked up few of them and got some basic idea. I still am stuck and that is why creating a new post to get some guidance. Scenario is this: My excel sheet has Y or N letter in A1, some text in B1 and a valid future date in C1. I currently have a VBA script that does this for ...

Help with rdply()

I love the progress bar with rdply() and I want to convert some of my loops (thanks to Hadley!). Is there a way to use a counter in rdply()? I need to accumulate values over replications. The code I want to convert is below. Thanks! reps <- 4 store <- numeric(4) c <- 0 for(i in 1:reps){c <- c + 1; store[i] <- c} store ...

When is it appropriate to use C++ Smart Pointers in GUIs (Programs with main loops)

Hi friends. I am leaning towards using std::tr1::shared_ptr to automatically manage a pointer to a utility class in my GUI program. Basically here's a skeleton of the program: int main () { Allocate dynamic memory for utility class GUI code.. GUI code... GUI Code.. GUI Main Loop } The program finishes when the user ca...

For loop in NVelocity.

Does NVelocity support #for loops? I've looked through the documentation and all I could find was the #foreach loop. I want to loop over a 2 dimensional array. ...

Java: Is `while (true) { ... }` loop in a thread bad? What's the alternative?

Is while (true) { ... } loop in threads bad? What's the alternative? Update; what I'm trying to to... I have ~10,000 threads, each consuming messages from their private queues. I have one thread that's producing messages one by one and putting them in the correct consumer's queue. Each consumer thread loops indefinitely, checking for a...

Ruby Nested Loop

Hi, I have a nested loop2(check2) in loop1(check1) but it seems that nested loop2(check2) only runs once. Both loops contain the same array. This script is used to check for a duplicate id in check1. check1=["0", "0", "0", "1", "1", "2", "3", "4", "5", "100", "4294967294", "9", "11", "6", "200", "7", "201", "811", "202", "204", "3000",...