Friday, April 10, 2009

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:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP