+7 votes
859 views
in Programming by (1.2k points)
I want to know the exact difference between if and else if with example.

thanks for help!
closed

1 Answer

+1 vote
by (2.8k points)
edited by
 
Best answer
See its very simple, if we are using "if" with  "else if" it means when if condtion is satisfy it will not go to else if condition , let's have a example for more clearaty .
 Let's say a=1 and b=2 .

if(a==1){
System.out.println("a is 1");
}else if(b==2){
System.out.println("b is 2");
}

Result will be a is 1

if(a==1){
System.out.println("a is 1");
}if(b==2){
System.out.println("b is 2");
}

Result will be a is 1
                         b is 2

I hope you got my point.

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated