• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method conditions not applying

 
ernest mcdermott
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Keith, heres the method in full:
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would put some print statements in the body of the if statements to see if they are being executed.
 
ernest mcdermott
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Keith, took your advice and got the problem.
Many thanks
Ernest
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic