Hi I have the following code:
medianListTester.cfyPE = 0;
if (medianListTester.cfyPE != 0 || testStock.getCEPS() != 0)
{
medianCYPE_price = medianListTester.cfyPE * testStock.getCEPS();
counter++;
}
else
//do something else
but it开发者_运维问答 doesn't seem to "do something else" and still fires the code inside the conditional. Am I doing something wrong here? Why won't it run the code in the if statement?
If testStock.getCEPS() is not 0 you will not hit the else block. Depending on what you need and what you are expecting you might need to use && instead of || ?
medianListTester.cfyPE is set to 0, so the first clause in your if statement evaluates to false. What does TestStock.getCEPS()? If that is non-zero, then that will evaluate to true, and the entire if statement is then true.
I can't really tell what you're asking, but you're calling getCEPS() twice, and perhaps that is returning two different values, and perhaps that is causing your trouble.
Try this instead:
medianListTester.cfyPE = 0;
var ceps = testStock.getCEPS();
if (medianListTester.cfyPE != 0 || ceps != 0)
{
medianCYPE_price = medianListTester.cfyPE * ceps;
counter++;
}
else
//do something else
It sounds like testStock.getCEPS()
is returning something other than 0. That would explain why it never hits do something else
. Have you checked what this is returning?
What's the value of the call to testStock.getCEPS()? If that's not 0 it will still enter that code block. Also, I don't know the details of the object referenced by medianListTester, but it is possible that there is a getter/setter that isn't working right.
Your best bet for solving this is to print out or somehow look at the values of both medianListTester.cfyPE and testStock.getCEPS() right after the assignment but just before the if statement.
精彩评论