Saturday 19 November 2016

The IF else selection 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 and when it’s 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 Failed if the student’s grade is less than 60. In either case, after printing occurs, the next pseudocode statement in sequence is “performed.” The body of the else is also indented. 
The preceding pseudocode If…else statement may be written in C as
Syntax:

if(condition)
{
   statements;
}
else
{
   statements;
}

Example:

if ( grade >= 60 ) 
{
   printf( "Passed" ); 
 else
 {
  printf("Failed");




2 comments: