if Statement

An “if “statement consists of a Boolean(test) expression followed by one or more statements.

In “if” control statement, respective block of code is executed when condition is true.

Syntax

if (testExpression) 
{
   // statements
}

About if Statement

The if statement evaluates the test expression inside parenthesis.

 

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

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

To learn more on test expression (when test expression is evaluated to nonzero (true) and 0 (false)), check out relational and logical operators.

Flowchart Of if Statement

if-flowchart

Program On if Statement

if-program

Output

if-output