在“for"循环中递增 1 时格式化背后的技术原因? [英] Technical reasons behind formatting when incrementing by 1 in a 'for' loop?
问题描述
在整个网络上,代码示例都有 for
循环,如下所示:
All over the web, code samples have for
loops which look like this:
for(int i = 0; i < 5; i++)
虽然我使用了以下格式:
while I used the following format:
for(int i = 0; i != 5; ++i)
我这样做是因为我相信它更有效,但在大多数情况下这真的很重要吗?
I do this because I believe it to be more efficient, but does this really matter in most cases?
推荐答案
我决定列出信息最丰富的答案,因为这个问题有点拥挤.
I have decided to list the most informative answers as this question is getting a little crowded.
DenverCoder8 的基准测试显然值得一些认可以及Lucas 编译的循环版本.Tim Gee 展示了 pre 和User377178 强调了 <和!=.Tenacious Techhunter 撰写了关于循环优化的一般性文章,值得一提.
DenverCoder8's bench marking clearly deserves some recognition as well as the compiled versions of the loops by Lucas. Tim Gee has shown the differences between pre & post increment while User377178 has highlighted some of the pros and cons of < and !=. Tenacious Techhunter has written about loop optimizations in general and is worth a mention.
你有我最喜欢的5个答案.
There you have my top 5 answers.
这篇关于在“for"循环中递增 1 时格式化背后的技术原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!