If arr
is an array of size 10, in the following code block, how many times is arr.length
accessed?
for (int i = 0; i < arr.length; ++i);
Once? Or every time it loops?
Thanks everyone! Here's what I ended up doing:
final int len = arr.length;
for (int i = 0; i < len; ++i);
Eleven times....
10 times, the statement i < arr.length
evaluates to true
.
1 time it evalutes to false
and the loop ends.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With