aspose file tools*
The moose likes Java in General and the fly likes method conditions not applying Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "method conditions not applying" Watch "method conditions not applying" New topic
Author

method conditions not applying

ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
hi everyone.
I have a piece of code that uses if else statements for conditions on 2d array elements. The problem however seems to be that they dont do anything. The condtions are in a while loop and an example of such is as follows:


the relevant clsing brackets etc are included later. My problem tho is that when i call the method none of the conditions seem to do anything. Any suggestions??
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Originally posted by ernest mcdermott:
hi everyone.
I have a piece of code that uses if else statements for conditions on 2d array elements. The problem however seems to be that they dont do anything. The condtions are in a while loop and an example of such is as follows:


the relevant clsing brackets etc are included later. My problem tho is that when i call the method none of the conditions seem to do anything. Any suggestions??


It's hard to say without seeing all the code, but if either of the first two conditions is true, then the rest of the if-else will not be executed.
ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
Sorry Keith, heres the method in full:
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I would put some print statements in the body of the if statements to see if they are being executed.
ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
Thanks Keith, took your advice and got the problem.
Many thanks
Ernest
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
You do realise that in this code
the second 'if' is superfluous. If the code reaches the 'else' then e[k][j] can only be not equal to 'before'. It can be written as
The same applies to the
code


Joanne
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: method conditions not applying
 
Similar Threads
How to make combination function generic
LinearProgramming in Java
Can this Java code convert to Javascript code
Priority First Search and Adjacency Matrix
Please help in this selection sort