I was wondering why you would choose to use a nested if or an Else If statement.
So I know the difference in code. I'm just wondering what the benefits of one or the other are.
QUESTION: nested If and Else If statement
Post a Reply
|Oldest Newest Rating|
· January 20, 2016
They are exactly the same.
So I'm not sure if you know, but when you use an if statement, the curly braces aren't required, the same goes with the else statement. When you don't include curly braces, Java assumes you want only the program statement after that to be part of the if-statement. For example:
The code segment above prints 30,000, as expected. However,
the above segment prints 30,000. Also, note that indentation is irrelevant.
So to answer your question about the benefits, there are no benefits. They are 100% the same efficiency. Personally, I prefer using "non-nested" Else If because it looks cleaner.
Java / Android Development
Very popular language used to create desktop applications, website applets, and Android apps.
|Bucky Roberts Administrator|