Top "For-loop" questions

A for loop is a control structure used by many programming languages to iterate over a range.

In .NET, which loop runs faster, 'for' or 'foreach'?

In C#/VB.NET/.NET, which loop runs faster, for or foreach? Ever since I read that a for loop …

c# .net performance for-loop
Continue For loop

I have the following code For x = LBound(arr) To UBound(arr) sname = arr(x) If instr(sname, "Configuration item") …

vba loops for-loop next
How can I print out C++ map values?

I have a map like this: map<string, pair<string,string> > myMap; And I've inserted some …

c++ dictionary for-loop printing std-pair
break statement in "if else" - java

I keep getting an error, if without else. I tried else if as well for (;;){ System.out.println("---> …

java if-statement for-loop infinite-loop break
What is the pythonic way to detect the last element in a 'for' loop?

I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last …

for-loop python idioms fencepost
Post-increment and pre-increment within a 'for' loop produce same output

The following for loops produce identical results even though one uses post increment and the other pre-increment. Here is the …

c++ c for-loop operator-precedence
How do I break out of a loop in Scala?

How do I break out a loop? var largest=0 for(i<-999 to 1 by -1) { for (j<-i …

scala for-loop break tail-recursion
Is it possible to declare two variables of different types in a for loop?

Is it possible to declare two variables of different types in the initialization body of a for loop in C++? …

c++ scope declaration for-loop
How to remove all null elements from a ArrayList or String Array?

I try with a loop like that // ArrayList tourists for (Tourist t : tourists) { if (t != null) { t.setId(idForm); } } But …

java performance loops for-loop arraylist
Is there a need for range(len(a))?

One frequently finds expressions of this type in python questions on SO. Either for just accessing all items of the …

python for-loop range