aspose file tools*
The moose likes Java in General and the fly likes How to check whether it's matching Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to check whether it Watch "How to check whether it New topic
Author

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

Andrew liu
Greenhorn

Joined: Nov 11, 2007
Posts: 3
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

Joined: Jan 01, 2007
Posts: 184
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


The significant problems we face cannot be solved by the same level of thinking which created them – Einstein
SCJP 1.5, SCWCD, SCBCD in the making
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to check whether it's matching "if" using "else"