Hi, I am using My.Settings in visual studio 2008 to store information, for when the user runs the program again.
I have that working fine... but as I am using 12 textboxes I don't want to write...
my.settings.grade1 = textbox1.text
for each one, and I am also making calculations using the stored information, so I dont want to be writi...
It is not uncommon for me (or likely anyone else) to have a list of objects I need to iterate through and then interact with a list of properties. I use a nested loop, like this:
IList<T> listOfObjects;
IList<TProperty> listOfProperties;
foreach (T dataObject in listOfObjects)
{
foreach (TProperty property in listOfProperties)
...
Note: This is NOT homework.
Hi,
It's easy to iterate over two variables and print their product like so:
for a in range(1,100):
for b in range(1,100): # or range(a,100) to prevent duplicates
print( "%s = %s * %s" % (a*b,a,b) )
However, is it possible to come up with a looping structure that will iterate over a and b in desc...
I've seen both the blocks of code in use several different times, personally I have always used the first but my question is: is there a functional difference, and if there is what is it?
while (condition is true ) {
// do something
}
do {
// do something
} while ( condition is true);
I will be applying this to PHP but I assu...
Hi there,
I am not sure what the problem is but I keep receiving this error when I try to use a while statement in my code.
Invalid token 'while' in class,
struct, or interface member
declaration
I want to use a while loop to have something continuously update while a statement is true.
The rest of my code is rather long but w...
A friend was in need of an algorithm that would let him loop through the elements of an NxM matrix (N and M are odd). I came up with a solution, but I wanted to see if my fellow SO'ers could come up with a better solution.
I'm posting my solution as an answer to this question.
Example Output:
For a 3x3 matrix, the output should be:
(...
Basically you have two ways for doing this:
for (int x = 0; x < UPPER_X; x++)
for (int y = 0; y < UPPER_Y; y++)
{
arr1[x, y] = get_value();
arr2[y, x] = get_value();
}
The only difference is what variable to change in the inner loop: first or second. I heard that the results differ from language to ...
Hi,
I have always wondered if, in general, declaring a throw-away variable before a loop, as opposed to repeatedly inside the loop, makes any (performance) difference?
A (quite pointless example) in Java:
a) declaration before loop:
double intermediateResult;
for(int i=0;i<1000;i++){
intermediateResult = i;
System.out.println...
The v4 series of the gcc compiler can automatically vectorize loops using the SIMD processor some modern CPUs, such as the AMD Athlon or Intel Pentium/Core chips. How is this done?
...
GCC can vectorize loops automatically when certain options are specified and given the right conditions. Are there other compilers widely available that can do the same?
...
Has anyone taken advantage of the automatic vectorization that gcc can do? In the real world (as opposed to example code)? Does it take restructuring of existing code to take advantage? Are there a significant number of cases in any production code that can be vectorized this way?
...
Is it better in some sense to vectorize code by hand, using explicit pragmas or to rely on or use auto-vectorization? For optimum performance using auto-vectorization, one would have to monitor the compiler output to ensure that loops are being vectorized or modify them until they are vectorizable.
With hand coding, one is certain th...
Hello, I want to know if it is possible to end a for loop in C++ when an ending condition (different from the reacheing right number of iterations) is verified. For instance:
for (int i = 0; i < maxi; ++i)
for (int j = 0; j < maxj; ++j)
// But if i == 4 < maxi AND j == 3 < maxj,
// then jump out of the two nested lo...
In other words, can I do something like
for() {
for {
for {
}
}
}
Except N times? In other words, when the method creating the loops is called, it is given some parameter N, and the method would then create N of these loops nested one in another?
Of course, the idea is that there should be an "easy" or "the usua...
In my Computer Science II class, the professor considers ++,--,*=, etc. to be 2 operations. However, at the Assembly level this is not really two operations. Can someone explain or is this just for the sake of simplicity?
...
Is there any way to know whether a MFC message loop is already running?
EDIT: Context: A library (with event handling) needs to know whether its event filtering has to attach to an existing MFC message loop or create its own message loop: in case a main message loop already exists it must not create its own loop because it would be bloc...
In Python, I've got a list if dictionaries that looks like this:
matchings = [
{'id': 'someid1', 'domain': 'somedomain1.com'},
{'id': 'someid2', 'domain': 'somedomain2.com'},
{'id': 'someid3', 'domain': 'somedomain3.com'}
]
and, I have a variable:
the_id = 'someid3'
What's the most efficient way to retrieve the domain v...
I've been learning C#, and I'm trying to understand lambdas. In this sample below, it prints out 10 ten times.
class Program
{
delegate void Action();
static void Main(string[] args)
{
List<Action> actions = new List<Action>();
for (int i = 0; i < 10; ++i )
actions.Add(()=>Console.WriteLine(i));
foreach (Action a in actio...
why are we using
for (int i = 0 ; i < count ; i++){ }
why the i
why not
for (int a = 0; a < count; a++){ }
I do it, you do it, everyone does it but WHY?
*edit
I found out an old saying about FORTRAN which is more funny than correct which says "god is real, everything else above is an integer".
"god" would be a variable name s...
I was wondering if there are any times where it's advantageous to use an IEnumerator over a foreach loop for iterating through a collection? For example, is there any time where it would be better to use either of the following code samples over the other?
IEnumerator<MyClass> classesEnum = myClasses.GetEnumerator();
while(classesEnum.M...