问题描述
for(i = 0,i< 3,i = i + 1)
for(i = 0; i< 4; i ++)
我不明白为什么它们相同.
I do not understand why they are same.
for(i = 0,i
将以i = 0开始,然后i = 0 + 1 = 1,i = 1 + 1 = 2,i = 2 + 1 = 3,然后3对i <3不满意,然后应该关闭.最终,它只重复3次,不是吗?(i = 0,1,2)
for( i=0, i<3, i=i+1 )
will start with i=0, then i=0+1=1, i=1+1=2, i=2+1=3, then 3 is not satisfied with i<3, then should close. So in the end, it repeats only 3 times isn't it? (i=0, 1, 2)
for( i=0; i
将以i = 0开始,然后i = 1,i = 2,i = 3,当达到i = 4时,如果4不满足i
for( i=0; i<4; i++ )
will start with i=0, then i=1, i=2, i=3, when reach i=4, 4 is not satisfied with i<4, then should close. So in the end, it repeats 4 times (i=0, 1, 2, 3).
我错了吗?
推荐答案
此
for( i=0, i<3, i=i+1 )
是无效的构造,将不会被编译.
is invalid construction and will not be compiled.
所以这些构造不一样,:)
So these constructions are not the same,:)
如果您甚至会在第一个构造中用逗号代替分号
And if you will even substitute commas for semicolons in the first construction
for( i=0; i<3; i=i+1 )
在任何情况下,它们都不相同,因为第一个循环只有3次迭代,而第二个循环只有4次迭代.
in any case they will not be the same because the first loop will have only 3 iterations while the second loop will have four iterations.
这篇关于for循环中的分号和逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!