On the move:

I'm currently moving the following to their own blogs: Unix, HTML for Blogs, Perl & Java.
The links are on the left side.

Tuesday, October 14, 2008

Java - If / Else vs. Switch

Both of these produce the exact same results:
if (opt == 1)
{
funcInst.func1();
}
else if (opt == 2)
{
funcInst.func2();
}
else
{
System.out.print("Invalid Option");
}
switch(opt)
{
case 1 : funcInst.func1() ;
break;
case 2 : funcInst.func2() ;
break;
default : System.out.print("Invalid Option");
break;
}


No comments:

Post a Comment