if-else Statement

The if-else statement executes some code if the test expression is true (nonzero) and some other code if the test expression is false (0).

Syntax

if (testExpression) {
    // codes inside the body of if
}
else {
    // codes inside the body of else
}

About if-else Statement

If test expression is true, code inside the body of if statement is executed; and code inside the body of else statement is skipped.

If test expression is false, code inside the body of else statement is executed; and code inside the body of if statement is skipped.

Flowchart Of if-else Statement

if-else-flowchart

Program On if-else Statement

if-else-program

Output

if-else-output