A semicolon terminates a statement. Loops need a statement attached, typically, to actually do something:Run that. Now add a ; to the end of the line with the for loop. Run it again.Code:#include<stdio.h>
int main( void )
{
int x = 0;
for( x = 0; x < 10; x++ )
printf( "x is %d\n", x );
return 0;
}
Without a pair of braces, only the immediate statement after a loop (or an if, or an else, etc.,) is attached:Note, it doesn't matter what line you have, but what actual statement is next:Code:if( x == 0 )
; // this statement is attached to the if
; // this one is not
Code:if( x == 0 )
; // this is attached to the if
Code:if( x == 0 ); // this ; is attached to the if
Quzah.