Link to home
Start Free TrialLog in
Avatar of Manoj Joshi, PMP
Manoj Joshi, PMPFlag for India

asked on

Java Code Flow problem

Hello Experts,
This might seem a bit weird, but here is what happens actually.
I'm using the following tools for my developmwnt environment:
IDE: eclipse Helios
Build tool : maven(using M2clipse through Eclipse)
jdk version : jdk 1.6 update 30(latest stable release for java6)

I have a skeleton of code which I would paste as below:

....
if(){

if(){
1. // some code inside
}//end of if
}
else{
if(){
2. //some part of code inside
}//end of if

}//end of else

.....

The code as you might have seen above is pretty simple one. However, I face a very strange problem when I run the debugger on the code. The debugging process shows that the from point 1 mentioned above suddenly moves into the point 2 (inside the else loop.)

Since the syntax for if-else clearly indicates that either if block is executed or the else loop is executed. However, in this case the cursor just moves from the inside of the inside of if loop(i.e point 1) and just suddenly drops into the else loops if loop (i.e point 2). There are no break or continue statements in between. Just simple code steps.

Only observation while debugging is that the condition in the inner if loop of the if loop (i.e point 1) returns null result. But still I do not understand why it should go into the the else loops if loop, if it has already gone into the first if loop.

I hope I have given enough information. If you need further information on this, kindly let me know. But can somebody please let me know why is this happening. If you have earlier faced this problem, or if you have known this, your help would be grateful.

Hope the mystery clears soon.

Kind Regards,
Manoj Joshi
Avatar of Kyle Hamilton
Kyle Hamilton
Flag of United States of America image

you could try writing it this way:

  
if () {

      // 1. // some code inside
                        
 } else if() {
                        
      // 2. //some part of code inside

 }//end of else/if 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Manoj Joshi, PMP
Manoj Joshi, PMP
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You're right, but it's not good coding practice to do it that way. It's redundant.
:)
Avatar of Manoj Joshi, PMP

ASKER

this is a duplicate thread . So closing it.