If statement question

# Thread: If statement question

1. Member
Join Date
Dec 1969
Posts
72

## If statement question

Hi there,<BR><BR>Is there anyway to check two conditions using the same if statement? ie:<BR><BR>if strSomething &#060;&#062; 9983 OR strSomething &#060;&#062; 9984 then

2. Senior Member
Join Date
Dec 1969
Posts
360

## RE: If statement question

Yes... did you try it.

3. Member
Join Date
Dec 1969
Posts
72

## RE: If statement question

Yeah, I just did. It works fine with just the first condition, but once I add the OR.... it doesn&#039;t work at all. Any thoughts?

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Pretend you are a computer.

Evaluate the statement yourself:<BR><BR> if strSomething &#060;&#062; 9983 OR strSomething &#060;&#062; 9984 then<BR><BR>[first of all, I have to ask whey you would be comparing a *STRING* named strSomething to an integer number! but we&#039;ll let that go]<BR><BR>Let&#039;s suppose that<BR> strSomething = 1111<BR><BR>SO:<BR> if strSomething &#060;&#062; 9983 OR strSomething &#060;&#062; 9984 then<BR><BR>Okay...So *IS* strSomething &#060;&#062; 9983? You betcha. That&#039;s true.<BR>And *IS* strSomething &#060;&#062; 9984? Yep! Also true.<BR><BR>So we just converted<BR> if strSomething &#060;&#062; 9983 OR strSomething &#060;&#062; 9984 then<BR>to<BR> if (strSomething &#060;&#062; 9983) OR (strSomething &#060;&#062; 9984) then<BR>and then to<BR> if (True) OR (True) then<BR>and of course if both are true then the OR doesn&#039;t even matter...it&#039;s all true.<BR><BR>That was the easy one.<BR><BR>******************<BR><BR>NOW let&#039;s say that<BR> strSomething = 9983<BR><BR>So *IS* strSomething &#060;&#062; 9983? NOPE! That&#039;s a big fat FALSE<BR>But then *IS* strSomething &#060;&#062; 9984? Yep! 9983&#060;&#062;9984! So that&#039;s true.<BR><BR>So we just converted<BR> if (strSomething &#060;&#062; 9983) OR (strSomething &#060;&#062; 9984) then<BR>to<BR> if (False) OR (True) then<BR>but when one is false and the other true, then OR says... the final answer is TRUE! So it&#039;s all TRUE.<BR><BR>***********************<BR><BR>One more.<BR><BR>NOW let&#039;s say that<BR> strSomething = 9984<BR><BR>So *IS* strSomething &#060;&#062; 9984? Yep. That&#039;s true.<BR>And then *IS* strSomething &#060;&#062; 9984? *NO*! NO! 9984&#060;&#062;9984 is FALSE!<BR><BR>So we just converted<BR> if (strSomething &#060;&#062; 9983) OR (strSomething &#060;&#062; 9984) then<BR>to<BR> if (True) OR (False) then<BR>but when one is false and the other true, then OR says... the final answer is TRUE! So it&#039;s all TRUE.<BR><BR>*********************<BR><BR>IN OTHER WORDS...<BR><BR>No matter WHAT value strSomething has, your test will *ALWAYS* find ONE (or both) of the separate conditions TRUE and so the entire test is TRUE!<BR><BR>*************<BR><BR>Dare I suggest that this is likely NOT what you wanted???<BR><BR>Maybe you wanted to use AND instead of OR?<BR><BR><BR><BR><BR>

5. Member
Join Date
Dec 1969
Posts
72

## RE: Pretend you are a computer.

Hmmm, obviously I wasn&#039;t thinking like a computer, and even if I was trying to, I wouldn&#039;t have been able to figure that out because I don&#039;t think I would have ever guessed that was the way it thought. Sort of like a woman. I have to put that one in my Men are from Mars, Computers are from Venus" notebook. :)<BR><BR>Thanks again Bill. Just put it on my tab. Man that tab is getting long!

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## I used to teach 6th graders...

...a before-school computer programming class.<BR><BR>We only had 3 or 4 computers, so we kept the class size down, so I got to do it several times. (These are kids who came to school 45 minutes early...at 7:10 AM...to learn programming in 6th grade!)<BR><BR>Anyway, first class with each new group I gave a little quiz to see who already knew what. And one of the questions was *always*:<BR><BR>Q: How smart is a computer?<BR> a) as smart as I am<BR> b) smarter than I am<BR> c) as smart as my dog<BR> d) as smart as a rock<BR> e) other<BR><BR>And of course the correct answer is (d). Computers don&#039;t THINK at all, actually. Computers just follow the very most basic instructions. One very very very tiny step at a time. So I guess when I say "pretend you are a computer", I&#039;m really saying "pretend you are a person who designs computer languages".<BR><BR>Anyway, for the last 55+ years, the rule for AND and OR operators have been the same, across hundreds of kinds of computers and hundreds of different computer languages.<BR><BR>True OR True --&#062;&#062; True<BR>True OR False --&#062;&#062; True<BR>False OR True --&#062;&#062; True<BR>False OR False --&#062;&#062; False<BR><BR>True AND True --&#062;&#062; True<BR>True AND False --&#062;&#062; False<BR>False AND True --&#062;&#062; False<BR>False AND False --&#062;&#062; False<BR><BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•