Loading, please wait...

If…else Statement

The if selection statement performs an indicated action only when the condition is true; otherwise the action is skipped. The if…else selection statement allows you to specify that different actions are to be performed when the condition is true than when the condition is false. For example, the pseudocode statement

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

Print “Passed”

else

Print “Failed”

prints Passed if the student’s grade is greater than or equal to 60 and prints Failed if the student’s grade is less than 60

if ( grade >= 60 ) {

printf( "Passed\n" );

} /* end if */

else {

printf( "Failed\n" );

} /* end else */