We all know that we can declare multiple variables in a for loop like the one below
for ( int var1 = 0, var2 = 0, var3 = 0, var4 = 0, var5 = 0, var6 = 0; var1 < 10;
var1++, var2++, var3++, var4++, var5++, var6++ )
{
int result = var1 + var2 + var3 + var4 + var5 + var6;
Console.WriteLine( result );
}
Console.Read();
My Question is,
- Can you let me know the total number of variables you can initialize in a for-loop?
- Do multiple variables affect the performance of for-loop?
- How many variable do you suggest we can use in a for-loop?
Thanks.
1
This is not about perfomance. Your only concern is readability, and that suffers a lot when you use a second variable. Never needed, never useful.