VB.Net 嵌套 If
VB.Net Nested If
我有一些逻辑,并且确定没有达到条件。我已经尝试了 if/ifelse/else 的几种变体来创建我想要的逻辑,但没有任何正确的工作。让我用一些代码告诉你...
If(a is true) Then
print("A is true")
Else If(b is true) Then
print("B is true")
if(c is true) Then
print("B and C are true")
else 'c is Not true
print("B is true, C is Not true)
if(d is true) Then
print("B and D are true")
else 'd is Not true
print("B is true, D is Not true")
End If
End If
End If
发生的事情是我的
"If(d is true)" 和 "else 'd is not true"
条件未检查。这部分逻辑是 "stepped over"
当 A、B、C 和 D 为真时的预期输出:
"A is true"
当 B、C 和 D 为真时的预期输出:
"B is true"
"B and C are True"
"B, C, and D are True"
当 B 和 C 为真但 D 不为真时的预期输出:
"B is true"
"B and C are True"
"B is true, D is not true"
当 B 和 D 为真时的预期结果:
"B is true"
"B is True, C is not true"
"B, and D are true"
我目前看到的:
B、C、D 为真:
"B is true"
"B and C are true"
其中省略了 "B and D are true"
希望这些结果能帮助您理解!
我不确定 a、b、c 或 d 是什么,但这是我认为您正在尝试做的。仅当 "d" 根据您的 "use case" 为真或假时,您才需要更改字符串。如果您想要更细粒度,那么我建议使用前面提到的字符串生成器。无论如何,这是我用来创建您的 "case" 的代码 要清楚,如果 "b" 为假,则永远不会检查 "c" 和 "d"。我是根据你的 "use case" 陈述的。
Private Sub Test()
Dim a = True
Dim b = False
Dim c = True
Dim d = True
Dim printout As String = ""
If a Then
printout = "a is true"
Else
If b Then
If c Then
printout = "b and c are true"
else
printout="b is true and c is not true"
End If
If d and c Then
printout = "b and c and d are true"
elseif d=true and c=false then
printout = "b and d are true , c is not true"
elseif c=true and d=false then
printout = "b and c is true ,d is not true"
else
printout = "b is true ,c and d are not true"
End If
End If
End If
Console.WriteLine(printout)
End Sub
我有一些逻辑,并且确定没有达到条件。我已经尝试了 if/ifelse/else 的几种变体来创建我想要的逻辑,但没有任何正确的工作。让我用一些代码告诉你...
If(a is true) Then
print("A is true")
Else If(b is true) Then
print("B is true")
if(c is true) Then
print("B and C are true")
else 'c is Not true
print("B is true, C is Not true)
if(d is true) Then
print("B and D are true")
else 'd is Not true
print("B is true, D is Not true")
End If
End If
End If
发生的事情是我的
"If(d is true)" 和 "else 'd is not true"
条件未检查。这部分逻辑是 "stepped over"
当 A、B、C 和 D 为真时的预期输出:
"A is true"
当 B、C 和 D 为真时的预期输出:
"B is true"
"B and C are True"
"B, C, and D are True"
当 B 和 C 为真但 D 不为真时的预期输出:
"B is true"
"B and C are True"
"B is true, D is not true"
当 B 和 D 为真时的预期结果:
"B is true"
"B is True, C is not true"
"B, and D are true"
我目前看到的:
B、C、D 为真:
"B is true"
"B and C are true"
其中省略了 "B and D are true"
希望这些结果能帮助您理解!
我不确定 a、b、c 或 d 是什么,但这是我认为您正在尝试做的。仅当 "d" 根据您的 "use case" 为真或假时,您才需要更改字符串。如果您想要更细粒度,那么我建议使用前面提到的字符串生成器。无论如何,这是我用来创建您的 "case" 的代码 要清楚,如果 "b" 为假,则永远不会检查 "c" 和 "d"。我是根据你的 "use case" 陈述的。
Private Sub Test()
Dim a = True
Dim b = False
Dim c = True
Dim d = True
Dim printout As String = ""
If a Then
printout = "a is true"
Else
If b Then
If c Then
printout = "b and c are true"
else
printout="b is true and c is not true"
End If
If d and c Then
printout = "b and c and d are true"
elseif d=true and c=false then
printout = "b and d are true , c is not true"
elseif c=true and d=false then
printout = "b and c is true ,d is not true"
else
printout = "b is true ,c and d are not true"
End If
End If
End If
Console.WriteLine(printout)
End Sub