How would you implement logical operators in DOS Batch files?
相关问题
- xcopy include folder
- Batch file if string starts by
- Jenkins - cmd is not recognized
- Does specifying the encoding in javac yield the sa
- String Manipulation with case sensitivity
相关文章
- 在vscode如何用code runner打开独立的控制台窗口,以及设置好调试模式时窗口的编码?
- Extracting columns from text file using Perl one-l
- How can one batch file get the exit code of anothe
- Command line escaping single quote for PowerShell
- How to make jenkins fail at a failing windows batc
- Problems using start-process to call other powersh
- Python utilizing multiple processors
- Why do all Pre-build or Post-build events in Visua
It's just as easy as the following:
AND> if+if
OR> if // if
I know that there are other answers, but I think that the mine is more simple, so more easy to understand. Hope this helps you! ;)
De Morgan's laws allow us to convert disjunctions ("OR") into logical equivalents using only conjunctions ("AND") and negations ("NOT"). This means we can chain disjunctions ("OR") on to one line.
This means if name is "Yakko" or "Wakko" or "Dot", then echo "Warner brother or sister".
This is another version of paxdiablo's "OR" example, but the conditions are chained on to one line. (Note that the opposite of
leq
isgtr
, and the opposite ofgeq
islss
.)Slight modification to Andry's answer, reducing duplicate type commands:
If you have interested to write an
if
+AND
/OR
in one statement, then there is no any of it. But, you can still groupif
with&&
/||
and(
/)
statements to achieve that you want in one line w/o any additional variables and w/oif-else
block duplication (singleecho
command forTRUE
andFALSE
code sections):Output:
The trick is in the
type
command which drops/sets theerrorlevel
and so handles the way to the next command.The following examples show how to make an AND statement (used for setting variables or including parameters for a command).
To close the CMD window and start Notepad:
To set variables x, y, and z to values if the variable 'a' equals blah.
Hope that helps!
Try the negation operand - 'not'!
Well, if you can perform 'AND' operation on an if statement using nested 'if's (refer previous answers), then you can do the same thing with 'if not' to perform an 'or' operation.
If you haven't got the idea quite as yet, read on. Otherwise, just don't waste your time and get back to programming.
Just as nested 'if's are satisfied only when all conditions are true, nested 'if not's are satisfied only when all conditions are false. This is similar to what you want to do with an 'or' operand, isn't it?
Even when any one of the conditions in the nested 'if not' is true, the whole statement remains non-satisfied. Hence, you can use negated 'if's in succession by remembering that the body of the condition statement should be what you wanna do if all your nested conditions are false. The body that you actually wanted to give should come under the else statement.
And if you still didn't get the jist of the thing, sorry, I'm 16 and that's the best I can do to explain.