for loop in C/C++
I have for开发者_如何学Go loop doubt that I need to ask .
once i saw in coding something like
for(i = 0; i<10; i+)
My doubt is why &when in for loop we use say i+
or i-
rather than i++
or i--
Thanks in advance
It won't work, doesn't the compiler return an error if you do? ( or atleast a warning.. )
Just use ++i or i++
Using i+
instead of i++
should not work. As I think you know, i++
increases the value of i
by one. When the compiler sees i+
, it is expecting something after the +
, which causes it to not compile.
The line in question is not valid C
for(i = 0; i<10; i+)
Some valid, equivalent (between themselves) options are
for(i = 0; i < 10; i++)
for(i = 0; i < 10; ++i)
for(i = 0; i < 10; i += 1)
for(i = 0; i < 10; ) { /*...*/ i++; }
You cannot use i+ or i- because if doesn’t work i.e doesn’t increase or decrease value of i for increment you have may use i++,++i,i+=1,i=i+1 and for decrement you can use these by changing sign to negtive
精彩评论