prev up next   top/contents search

comp.lang.c FAQ list · Question 16.1

Q: Why is this loop always executing once?

	for(i = start; i < end; i++);
		{
		printf("%d\n", i);
		}


A: The accidental extra semicolon hiding at the end of the line containing the for constitutes a null statement which is, as far as the compiler is concerned, the loop body. The following brace-enclosed block, which you thought (and the indentation suggests) was a loop body, is actually the next statement, and it is traversed exactly once, regardless of the number of loop iterations.

See also question 2.18.

References: CT&P Sec. 2.3 pp. 20-21


prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North