What I want this to do is increment x by 1 repeatedly and print the current value of x at any given time until it reaches 1000, in which case it should add the word "finally". When I compile and run this code it increments x all the way up to 1000 but when it reaches 1000 it simply prints "X is equal to 1000.", ignoring the condition of the if statement that encloses it.

I think the problem is that the for loop wants to increment x until x is less than or equal to 1000, but at that point I want the if function to take over, and print its message. I'm not really sure how to go about doing that.

Thanks. Could you explain exactly why it has to be in that order? Because to me the most logical thing to do is check whether x is equal to 1000 and if it's not, increment it.

Because a program is executed sequentially. Your if statement is executed before the loop (when x == 0).
The loop compromises all of the statements in the enclosing braces of the for (that is, the if is outside the loop!).
Btw, you should indent properly.

Originally Posted by Adak

io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

Originally Posted by Salem

You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.