Loading, please wait...

If Statement

Selection structures are used to choose among alternative courses of action. For example, suppose the passing grade on an exam is 60. The pseudocode statement

If student’s grade is greater than or equal to 60

Print “Passed” determines if the condition “student’s grade is greater than or equal to 60” is true or false. If the condition is true, then “Passed” is printed, and the next pseudocode statement in order is “performed”. If the condition is false, the printing is ignored, and the next pseudocode statement in order is performed. The second line of this selection structure is indented. Such indentation is optional, but it’s highly recommended as it helps emphasize the inherent structure of structured programs. The C compiler ignores white-space characters like blanks, tabs, and newlines used for indentation and vertical spacing.

Consistently applying responsible indentation conventions greatly improves program readability.

The preceding pseudocode If statement may be written in C as

if ( grade >= 60 ) {

printf( "Passed\n" );

} /* end if */