Author Topic: Using And / Or  (Read 3584 times)


  • Newbie
  • *
  • Posts: 12
Using And / Or
« on: January 30, 2014, 08:26:36 am »
Cannot for the life of me find anything about using AND / OR in an IF THEN statement when you want to conditions to be evaluated at the same time. I did find an example in help where this symbol was used || but still not clear how that gets evaluated.

Thanks in advance,


  • Pundit
  • *****
  • Posts: 1832
    • Data & Stuff Inc.
Re: Using And / Or
« Reply #1 on: January 30, 2014, 08:38:55 am »
Look in the Help file under "Operators".

|| - Logical Or
&& - Logical And



  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Using And / Or
« Reply #2 on: January 30, 2014, 09:12:06 am »
The logical And & OR operators are documented under the topic "Operators" in the Windows Interface Language  help file.  See the "Conditional Statements" topic for some examples of conditional code. Also all of the conditional statements have there own topic in the Windows Interface Language help file.

Here is a code sample to help get you started.
Code: Winbatch
;Check if a number is between 1 and 10
x = 5
If x>0 && x<=10
  Pause( 'Result', x : ' is between 1 and 10' )
  Pause( 'Result', x : ' is NOT between 1 and 10' )

Deana F.
Technical Support
Wilson WindowWare Inc.


  • Sr. Member
  • ****
  • Posts: 330
Re: Using And / Or
« Reply #3 on: January 30, 2014, 09:25:59 am »
Do be aware, though, that although they look the same, the && and || operators in WinBatch do not behave like their C/C++ (and most/all other "C-like" languages) counterparts.

That is, they do not implement the "short circuit evaluation", which is central to how these operators work in those other languages.  That is, if you write:

IF someFunction(...) && someOtherFunction(...) THEN ...

both function calls (someFunction() and someOtherFunction()) will be evaluated, regardless of whether or not someFunction() returns true or false.

In most/all other C-like languages, if someFunction() returns false, someOtherFunction() will not be evaluated.

Now, many people will argue that this doesn't matter and that this whole post is a meaningless nitpick, but the fact is that this "short circuit" method is central to how these operators work and is widely used in both C-like and LISP-derived languages.  Once you get used to using it (say, in LISP), you will not see it as meaningless.

To clarify this last point further, LISP has functions AND(...) and OR(...) which mean, literally, evaluate expressions until one returns NIL (false), and evaluate expressions until one returns non-NIL (true), respectively.  Very powerful in the context of LISP.

I have implemented a UDS that does short-circuit evaluation in WinBatch.  I use it frequently when I need this behavior.


  • Newbie
  • *
  • Posts: 12
Re: Using And / Or
« Reply #4 on: January 30, 2014, 09:31:04 am »
Thank you