if-else-if Control Statement
The if-else-if Control Statement
A common programming construct that is based on nested if's is if-else-if ladder construct.In it the if condition is followed by else if conditions which are executed in drop down fashion if first if is not executed then program flow takes it to nest else if condition and so on.
Syntax:-
if(condition)
statement;
else if(condition)
statement;
else if(condition)
statemet;
....
else
statement;
The if statement are executed from top to bottom.As soon as one if condition becomes true then respective statements are exceuted and rest of conditions are bypassed.If none of condition is true then final else statemenst are executed.This final else statement acts as default condition.If there is no else condition and no if condition is true then no action will occur.
Example:-
if(salary<1000)>1000)
System.out.println("Job Grade 3");
else if(salary<4000&&salary>2500)
System.out.println("Job Grade 2");
else
System.out.println("Job Grade 1");


















0 comments:
Post a Comment
Post a Comment