In a for-loop, is a calculated expression re-calculated on each pass through
the loop, or only once, when the loop is initialized? For example, assume
the following loop:
for (int i = 0; i < myArray.Length - 1; i++)
{
// code here
}
Is "myArray.Le ngth - 1" calculated once, or on each pass through the loop?
Or, to put it another way, is there any advantage to:
int n = myArray.Length - 1;
for (int i = 0; i < n; i++)
{
// code here
}
Thanks in advance.
--
Dave Veeneman
Chicago
the loop, or only once, when the loop is initialized? For example, assume
the following loop:
for (int i = 0; i < myArray.Length - 1; i++)
{
// code here
}
Is "myArray.Le ngth - 1" calculated once, or on each pass through the loop?
Or, to put it another way, is there any advantage to:
int n = myArray.Length - 1;
for (int i = 0; i < n; i++)
{
// code here
}
Thanks in advance.
--
Dave Veeneman
Chicago
Comment