Which of these pieces of code is faster in Java?

前端 未结 16 2041
囚心锁ツ
囚心锁ツ 2020-11-30 04:25

a) for(int i = 100000; i > 0; i--) {}

b) for(int i = 1; i < 100001; i++) {}

The answer is t

16条回答
  •  孤城傲影
    2020-11-30 04:55

    The answer is a (as you probably found out on the website)

    I think the reason is that the i > 0 condition for terminating the loop is faster to test.

提交回复
热议问题