• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Code Won't Compile...If/Else Problems?

 
Kenneth Kim
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code won't compile...it always says that I have an else without an if...take a look!

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've got lots of extra semicolons like the one below which are causing the error:

else if (something);

There should be no semicolon after those parentheses
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try taking out the semi-colons at the end of each else-if statement, for starters.
 
Kenneth Albertson
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kim, as a good general rule, you will find both syntax and logic errors easier to find if you try to keep your code as simple as possible.

For example, you only need to test fstatus.equalsIgnoreCase("single") once.

Then, once you know that (tincome <= 7300) has failed, there is no need to test for (tincome > 7300), and so on.

Use these guides to restructure your if statements. You will find the resulting logic much simpler, easier to understand, and easier to debug.

It will also be more efficient, but that is off less importance.
[ September 26, 2005: Message edited by: Kym Thompson ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic