To keep it simple,
in case A,
- your program has to initialize
ionly once. - Assign values to
ionlyarray.Lengthtimes. - Increase
ivalues onlyarray.Lengthtimes. - do the line execution and comparison 2*
array.Lengthtimes.
In case B,
- initialize
itwice. - Assign values to
i2*array.Lengthtimes. - Increase
ivalues 2*array.Lengthtimes. - do line execution and comparison 2*
array.Lengthtimes.
So, which one you would prefer?
solved for Loop commands – which is faster?