for-loop

For loop with onRollOver problem

Hi, I can't get this For loop with onRollOver to work. for (var i:Number = 1; i<=4; i++) { this['videobutton'+i].onRollOver = function() { trace(i); this['stream'+i].pause(false); this['video'+i].attachVideo(this['stream'+i]); fadeIn(this['video'+i]); }; } It think it has to do with variable scope and the i, but I don'...

What does a C# for loop do when all the expressions are missing. eg for(;;) {}

I can only assume it's an infinite loop. Can I leave out any of the three expressions in a for loop? Is there a default for each when omitted? ...

Netstream() loop problem

I'm preloading 4 flv movies and hide them, when I rollover the videobutton movieclip i want the flv video to fade in and start playing. I have this working code, but I feel it's very badly written. var videos:Array = new Array( 'ltp_video-low1.flv', 'ltp_video-low1.flv', 'ltp_video-low1.flv', 'ltp_video-low1.flv' ); function videoOver(...

Does it change performance to use a non-int counter in a loop?

I'm just curious and can't find the answer anywhere. Usually, we use an integer for a counter in a loop, e.g. in C/C++: for (int i=0; i<100; ++i) But we can also use a short integer or even a char. My question is: Does it change the performance? It's a few bytes less so the memory savings are negligible. It just intrigues me if I do a...

how to iterate in reverse over a map in c++

I'm having trouble iterating in reverse over a map in gcc c++. When I use a reverse iterator, it seems I can't assign anything to it - the compiler complains. I'm working around it with some awkward code using a forward iterator, but it's not very elegant. Any thoughts? ...

How do I apply a shell command to many files in nested (and poorly escaped) subdirectories?

Hi! I'm trying to do something like the following: for file in `find . *.foo` do somecommand $file done But the command isn't working because $file is very odd. Because my directory tree has crappy file names (including spaces), I need to escape the find command. But none of the obvious escapes seem to work: -ls gives me the spa...

Why is "while" so popular in C#?

The question field is a bit too short to pose my real question. If anyone can recapitulate it better, please feel free. My real question is this: I'm reading a lot of other people's code in C# these days, and I have noticed that one particular form of iteration is widely spread, (see in code). My first question is: Are all these iter...

c++ for loop vs foreach

Which is better( or faster) c++ for loop or the foreach operator provided by Qt? For example,the following condition QList listofstrings; Which is better? foreach(QString str, listofstrings) { //code } or int count = listofstrings.count(); QString str = QString(); for(int i=0;i<count;i++) { str = listofstrings.at(i); //code } ...

Finding how a foreach collection gets modified

Hello everyone, How do I find out which function or target is modifying the items in a foreach loop in a multithreaded application? I continously keep getting the error "Collection was modified; enumeration operation may not execute". I'm not removing or adding any items to the generic list within the for loop. I want to find out how it...

Beginner for loop problem

[EDIT]Whoops there was a mistake in the code, and now all the responses to the question seem bizzare, but basically the for loop used to be, for(i=0; i<15; i++). I also edited to make the question more clear.[/EDIT] I am trying to make a for loop, that checks a 16 element array, so it loops from 0 to 15. I then use the i variable later,...

Counting down in for-loops

I believe (from some research reading) that counting down in for-loops is actually more efficient and faster in runtime. My full software code is C++ I currently have this: for (i=0; i<domain; ++i) { my 'i' is unsigned resgister int, also 'domain' is unsigned int in the for-loop i is used for going through an array, e.g. array[i] =...

Is it possible to implement a Python for range loop without an iterator variable?

Is is possible to do this; for i in range(some_number): #do something without the i? If you just want to do something x amount of times and don't need the iterator. ...

c++ loop macros.

I use macros to code unrolled loops like this: (silly example) #define foreach_small_prime(p, instr) { \ int p; \ p = 2; instr; \ p = 3; instr; \ p = 5; instr; \ p = 7; instr; \ } foreach_...

Python Iterator Help + lxml

I have this script- import lxml from lxml.cssselect import CSSSelector from lxml.etree import fromstring from lxml.html import parse website = parse('http://xxx.com').getroot() selector = website.cssselect('.name') for i in range(0,18): print selector[i].text_content() As you can see the for loop stops after a number of ti...

How to loop through multiple arrays?

Hi, I'm new to this, so sorry if my question has been asked before. I have searched but have not been able to find, or perhaps recognise, an answer. I am using visual studio 2008 and creating an app in vb.net. I have 4 arrays named:- account1 account2 account3 account4. They all have 4 elements. I want to assign values to the elements i...

Django template for loop

I have a basic question, in the Django template language how can you tell if you are at the last loop iteration for a "for loop"? ...

Is there any performance difference between for() and while()?

Or is it all about semantics? ...

Faster way to sum a list of numbers than with a for-loop?

Is there a way to sum up a list of numbers faster than with a for-loop, perhaps in the Python library? Or is that something really only multi-threading / vector processing can do efficiently? Edit: Just to clarify, it could be a list of any numbers, unsorted, just input from the user. ...

Is there a way to define variables of two types in for loop?

This works: int main() { for (int i = 0, j = 0; i < 10; i += 1, j = 2*i) { cout << j << endl; } } ` But this not: int main() { for (int i = 0, float j = 0.0; i < 10; i += 1, j = 2*i) { cout << j << endl; } } Is there a way to define variables of two types in for loop? I don't need to use iterator i inside the loop, ...

some students asked me why do we need to have loop in a program, and they just won't accept that it is needed

some junior high school students asked me why do we need to have loop in a program, and they just won't accept that it is needed... i already told them if we need to find the average and standard deviation of 100 numbers, we can put the numbers in an array by a loop, and then we can find the average, standard deviation, or print the numb...