3 ms·
I would call using the first example good programming and not an optimization. Anytime a loop is involved it is simply good practice to limit calling anything m
by matwood 12y ago
I would call using the first example good programming and not an optimization. Anytime a loop is involved it is simply good practice to limit calling anything multiple times unless absolutely necessary.
A second reason the first is better is that it clearly conveys to the next programmer that there is no intention for myString to change length during the running of the loop. If I came across the second example I would wonder if the length of myString was changing in the loop.