WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: geauga on July 16, 2015, 10:54:45 AM

Title: How do you do boolean "and" or "or" tests?
Post by: geauga on July 16, 2015, 10:54:45 AM
I need to evaluate two different variables using ââ,¬Å"andââ,¬Â or ââ,¬Å"orââ,¬Â logic and I cannot seem to come up with the correct "If" statement syntax.  Does anybody have suggestions   for the following two statements?

If a == ââ,¬Å"5ââ,¬Â and b == ââ,¬Âfredââ,¬Â then goto label 
If a == ââ,¬Å"5ââ,¬Â or b == ââ,¬Âfredââ,¬Â then goto label 
Title: Re: How do you do boolean "and" or "or" tests?
Post by: JTaylor on July 16, 2015, 11:54:13 AM
Use "&&" for "and"

Use "||" for "or"

More info can be found in the Help File under "Operators".

Jim
Title: Re: How do you do boolean "and" or "or" tests?
Post by: geauga on July 16, 2015, 12:57:22 PM
Thanks.  I had looked in the Help file and rummaged through various examples from other perople and must have missed theses.  Thanks again.
Title: Re: How do you do boolean "and" or "or" tests?
Post by: snowsnowsnow on July 17, 2015, 05:41:17 AM
Do be aware, though, that WinBatch's && and || operators do not work the same way as the identically spelled operators do in C and all other (to the best of my knowledge) C-derived languages (e.g., C++, AWK, Perl, etc).

So, if you are familiar with any of those other languages, finding out how it works in WinBatch can be something of a shock.
Title: Re: How do you do boolean "and" or "or" tests?
Post by: td on July 17, 2015, 06:57:00 AM
Quote from: geauga on July 16, 2015, 12:57:22 PM
Thanks.  I had looked in the Help file and rummaged through various examples from other perople and must have missed theses.  Thanks again.

If you open the Consolidated WIL Help file and click on the 'Contenst' tab you can find the language operator documentation by clicking on Windows Interface Language Reference -> Things to Know -> Operators. 

And don't let snow++ scare you. WIL operators aren't all that difficult for even geriatric programmers... 


Title: Re: How do you do boolean "and" or "or" tests?
Post by: snowsnowsnow on July 17, 2015, 01:48:25 PM
How old do you have to be to qualify as a "geriatric programmer" ?

Note, BTW, that the difference is that WIL's implementation of && and || is simpler than in C (so probably easier for geriatric programmers to understand...).

I've always wondered why they didn't go the extra mile to make it work like it does in C.
Title: Re: How do you do boolean "and" or "or" tests?
Post by: td on July 17, 2015, 02:10:35 PM
Quote from: snowsnowsnow on July 17, 2015, 01:48:25 PM
How old do you have to be to qualify as a "geriatric programmer" ?

I don't know. Maybe if you're fluent in two or three of the following: Cobol, C, Simula 67, Common LISP, Smalltalk-80, or Fortran 77?

Quote
Note, BTW, that the difference is that WIL's implementation of && and || is simpler than in C (so probably easier for geriatric programmers to understand...).

I suspect ease depends to some degree on your previous programing and scripting experience.

Quote
I've always wondered why they didn't go the extra mile to make it work like it does in C.

Because it's much farther than a mile.
Title: Re: How do you do boolean "and" or "or" tests?
Post by: snowsnowsnow on July 17, 2015, 02:28:13 PM
QuoteBecause it's much farther than a mile.

Interesting.  I'm guessing that the way WIL is setup, everything gets eval'd before anything gets executed, and it would be more than a bit difficult to change that.
Title: Re: How do you do boolean "and" or "or" tests?
Post by: DAG_P6 on July 28, 2015, 06:00:11 PM
Also be aware that A | B is not the same as A || B.
The same holds for A & B is not the same as A && B.

Also, when in doubt, parenthesize.