Explain if statement with example
IF Statement
Selection structure:
Used to choose among alternative courses of action
Pseudocode:
If student’s grade is greater than or equal to 60Print “Passed”
If condition true
Print statement executed and program goes on to next statement
If false, print statement is ignored and the program goes onto the next statement
Indenting makes programs easier to read
C ignores whitespace characters
Pseudocode statement in C:
if ( grade >= 60 ) printf( "Passed\n" );
C code corresponds closely to the pseudocode
Diamond symbol (decision symbol)
Indicates decision is to be made
Contains an expression that can be true or false
Test the condition, follow appropriate path
if structure is a single-entry/single-exit structure
Labels: C