Computer Applications

Explain if-else-if construct

Input in Java

12 Likes

Answer

It is used when more than one condition are to be evaluated and only one of them is true.

The syntax of if-else-if construct is as follows:

if(condition 1)     
Statement 1     //executed if condition 1 is true
else if(condition 2)
Statement 2     //executed if condition 2 is true
else
Statement 3     //executed if both conditions 1 and 2 are false

When 'condition 1' is 'True' then it will execute statement 1. In case 'condition 1' is false, the control will move to 'else if' part and will check 'condition 2'. If it is true, the control will execute 'Statement 2' otherwise it will execute 'Statement 3'.

Answered By

7 Likes


Related Questions