Beginners question

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I have a basic question about if statements. Is this the right way to
have an if statement if (condition a or condition b) then ...

if ((strCash != "" && blnValidRSValue == true) || (strCash == ""))


Thanks,

Mike
 
Mike P said:
I have a basic question about if statements. Is this the right way to
have an if statement if (condition a or condition b) then ...

if ((strCash != "" && blnValidRSValue == true) || (strCash == ""))

Yup, that seems fine to me. Is there any particular concern you were
worried about?

Note that although the above is logically sound, it could be simplified
to:

if (strCash=="" || blnValidRSValue==true)
 
Hi Mike,

That would be perfectly legal. An if statement can contain any number of
sub conditions as long as they all can be handled as true or false.

In your case it would read
if (condition 1 AND condition 2) OR condition 3
do stuff

This would be the same as

if(strCash == "")
do stuff
else if(blnValidRSValue == true)
do same stuff

In fact, since || is the Conditional OR (if condition 1 AND 2 is true,
condition 3 will never be checked). If you do it the other way around

if(strCash == "" || blnValidRSValue == true)

would be the same, and easier to read too.

Is strCash empty? If not, is blnValidRSValue true?

Hope this helps,
Morten
 
Yup, that seems fine to me. Is there any particular concern you were
worried about?

Note that although the above is logically sound, it could be simplified
to:

if (strCash=="" || blnValidRSValue==true)

Err....it is never necessary to test against the values of /true/ or
/false/...just use...

if (strCash=="" || blnValidRSValue)

But I am sure you already knew that :O)

Oz
 
Back
Top