The structure of an if statement is as follows:
if ( statement is TRUE )
Execute this line of code
Here is a simple example that shows the syntax:
if ( 5 < 10 )
printf( "Five is now less than ten, that's a big surprise" );
Here, we're just evaluating the statement, "is five less than ten", to see if
it is true or not; with any luck, it's not! If you want, you can write your
own full program including stdio.h and put this in the main function and run
it to test.To have more than one statement execute after an if statement that evaluates
to true, use braces, like we did with the body of the main function. Anything
inside braces is called a compound statement, or a block. When using if
statements, the code that depends on the if statement is called the "body" of
the if statement.
For example:
if ( TRUE ) {
/* between the braces is the body of the if statement */
Execute all statements inside the body
}
No comments:
Post a Comment