C if…else Statement

C if statement

if (testExpression) {   // statements}

The if statement evaluates the test expression inside the parenthesis.

If the test expression is evaluated to true (nonzero), statements inside the body of if is executed.

If the test expression is evaluated to false (0), statements inside the body of if is skipped from execution.

Flowchart of if statement

C 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 of if…else

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

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

Flowchart of if…else statement

Nested if…else statement (if…elseif….else Statement)

The if…else statement executes two different codes depending upon whether the test expression is true or false. Sometimes, a choice has to be made from more than 2 possibilities.

2 thoughts on “C if…else Statement

Leave a Reply

Your email address will not be published.