
A loop that decrements is sometimes fastest. You want to optimize loops by testing your iteration variable against zero. This works in many programming languages, not only the C# language. You can often make your loops to go faster by using decrement instead of increment.
This C# performance article shows how to decrement loops as an optimization.
Decrementing loop performance test Increment down to zero: 644 ms Increment up to max: 852 ms
First, you can change loops to test against zero, which can sometimes slightly enhance performance. This also works in C++ and many other languages. The approach is called testing against 0 and iterating down, decrementing, instead of up. The code was benchmarked and the version that tests against zero was found to be faster. The difference here is minimal.
Program that decrements for loop [C#]
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
int val = 0;
const int m = 10;
const int max = 100000000;
for (int x = 0; x < 10; x++)
{
Stopwatch s1 = Stopwatch.StartNew();
for (int i = 0; i < m; i++)
{
for (int a = max - 1; a >= 0; --a)
{
if (val++ > 1000)
{
val = 0;
}
}
}
s1.Stop();
Stopwatch s2 = Stopwatch.StartNew();
for (int i = 0; i < m; i++)
{
for (int a = 0; a < max; a++)
{
if (val++ > 1000)
{
val = 0;
}
}
}
s2.Stop();
Console.WriteLine("{0},{1}",
s1.ElapsedMilliseconds,
s2.ElapsedMilliseconds);
}
}
}
Output
647,852
644,852
643,855
644,853
643,851
642,852
643,852
644,852
643,851
643,853
Testing against zero. The reason testing against the zero value is faster is possibly because X86 chips, including Pentium, Celeron, Core 2 Duo, and AMD Athlon, have special instructions and optimizations for this test.

Here we saw how you can decrement loops in an interesting micro-optimization. Decrementing a variable in a loop is twice as fast. On a modern 2 GHz computer, this will save you 1 millisecond per million iterations. That means testing against zero is a millionth of millisecond faster. This is of extremely minimal value in 99% of programs. Finally, you can find more general information about incrementing and decrementing for-loops here.
For Loops Loop Constructs