This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to check whether it Watch "How to check whether it New topic

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

Andrew liu

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
I agree. Here's the link:
subject: How to check whether it's matching "if" using "else"
It's not a secret anymore!