can't put an if statement as an increment in a for loop. Why?
I'm a novice, but I've put plenty of effort into figuring this out myself, and I'm baffled. When I look up the format for a for loop, it says there should be an "expression" in each of the three spots. an if statement counts as a single expression, no? But this:
1 #include <stdio.h>
2
3 int main(void)
4 {
5 int i;
6
7 for (; i < 10; if (1) i++);
8
9 return 0;
10 }
gives me the error:
forLoopTest.c:7: error: expected expression before ‘if’.
and I found ten different examples of people fixing the error "expected expression before" . . . , and they all looked like totally different problems.
I know it doesn't work, and I can't think of any reason I'd need to use an if statement there, but I'm curious why the if statement doesn't work. And knowing what that error means would actually be useful.
|