Hey there! any question in your mind? Ask It Now!.

Popular Categories





What is exact difference between if and else if ?

+7 votes
516 views
asked in Programming by jazs (1,220 points)
I want to know the exact difference between if and else if with example.

thanks for help!

1 Answer

+1 vote
answered by monika (2,040 points)
edited by monika
 
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.

Related Questions

+15 votes
2 answers 7,012 views
+7 votes
8 answers 7,422 views
+1 vote
2 answers 68 views
0 votes
0 answers 107 views
0 votes
5 answers 581 views
+5 votes
1 answer 149 views
asked in Programming by mannu (990 points)
+1 vote
1 answer 265 views
0 votes
1 answer 99 views
0 votes
0 answers 100 views

Not a Member yet?

Ask to Folks Login

My Account
453 Folks are online
1 members and 452 guest online
Your feedback is highly appreciated