vbs代码中的逻辑运算符nor、or、and如何使用?结合例子说明
在VBS代码中,逻辑运算符NOR、OR、AND用于对布尔类型的值进行逻辑运算。
NOR运算符表示逻辑非或,当所有操作数都为False时,返回True,否则返回False。OR运算符表示逻辑或,当至少有一个操作数为True时,返回True,否则返回False。AND运算符表示逻辑与,当所有操作数都为True时,返回True,否则返回False。
下面是使用这三个逻辑运算符的例子:
Dim a, b, c, d
a = True
b = False
c = True
d = False
' NOR运算
If Not (a NOR b) Then
WScript.Echo "a NOR b is True"
End If
' OR运算
If (a OR b) Then
WScript.Echo "a OR b is True"
End If
' AND运算
If (c AND d) Then
WScript.Echo "c AND d is True"
Else
WScript.Echo "c AND d is False"
End If
运行以上代码,输出结果为:
a NOR b is True
a OR b is True
c AND d is False
在第一个条件判断中,由于a和b都是True,所以a NOR b的结果为False,因此条件判断为False,不会输出结果。
在第二个条件判断中,由于a为True,所以a OR b的结果为True,因此条件判断为True,输出结果为a OR b is True。
在第三个条件判断中,由于c为True而d为False,所以c AND d的结果为False,因此条件判断为False,输出结果为c AND d is False
原文地址: https://www.cveoy.top/t/topic/h9Bx 著作权归作者所有。请勿转载和采集!