Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question re: nested IF statements

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following nested if statements whereby I am trying to launch the action code to work in either case. Would someone please let me know what I am doing wrong and how I can make this work without having to duplicate the action code in an else statement because it is pretty long?

Here is my code:

if (readRequest.getTransactionID() != null &&
readRequest.getTransactionID().intValue() == Transaction.get(readRequest.getTransactionID()).GetId()){
if (readRequest.getTransactionID() == null){
Transaction transaction = new Transaction(); readRequest.setTransactionID(BigInteger.valueOf(transaction.GetId()));
ACTION CODE}
}

Thank you.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its a good idea if you are slightly confused about the logic for a conditional statement to write out what you want to do in English before trying to do it with code. If you do you might spot why the code inside your nested conditinal statement will never run. (Hint: look at the null checks)
[ August 24, 2005: Message edited by: Paul Sturrock ]
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you introduce some variables to simplify this, at least one for readRequest.getTransactionID().
 
suresh koutam
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i understood ur code correctly..then i know where u are doing the mistake..
see ur if conditions....
the first IF will aloow u inside the loop only if the two conditions are met...where the first one is not a null...
so when the transactionId is not a null and the other condition is true it enters the loop...then check the second IF....
u are checking for NULL again....
remember when the transaction ID is not NULL it entered the loop..how can it be null inside....
u have to hcange the condition...
U are contradicitng ur IF statments...
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

Thanks so much for all the help. Marilyn, thanks especially for the link to the additional info it was very helpful.

Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic