i

R Programming Complete Tutorial

If…else if…Else Statement

In case of multiple else if, the system checks more than one condition.

Flow Diagram:

 If condition one is true, it will execute statement 1; in case of FALSE, it will check the second condition, and if the second condition is true.

Syntax:

The syntax is similar to if-else, but they will appear multiple times.

Example:

This if…else…if..else condition will update the salary of all the employees.

First, it will take the employee category from the user prompt. If the category is G1, the updated salary will be double; in case of G2, it will be 1.8 times, and else the salary will be 1.2 times.