File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to check whether it's matching "if" using "else"

 
Andrew liu
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recently, i meet a problem. According to our coding rule, we should use keyword "else" to match keyword "if". I want to check that.
Now, i used Stack to check whether the program has the mismatching. But i cannot accurately indicate where the mismatching occus.
Such as:
1 if (true) {
2 // something omitted...
3 } else {
4 if {
5 // something omitted...
6 }
7 }

In line 4, the mismatching occurs. But how can i indicate it?
 
abhishek pendkay
Ranch Hand
Posts: 184
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JAVA law says
that an else clause belongs to the innermost if statement to which it might
possibly belong (in other words, the closest preceding if that doesn't have an else).
Think about this law and then try to figure out where in your code the mismatch occurs
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic