我已经在VB中制作了Baa Baa Black Sheep,并且陷入了程序的最后阶段。我试图让程序声明用户是否为拥有行李的人输入了正确的信息,但似乎没有注册最后一部分。任何帮助是极大的赞赏!
Module Module1
Sub Main()
Dim WoolAnswer As String = ""
Dim BagNumber As Integer = 0
Dim FirstBag As String = ""
Dim SecondBag As String = ""
Dim ThirdBag As String = ""
Console.WriteLine("Do you have any wool?")
WoolAnswer = Console.ReadLine
If WoolAnswer = "yes" Then
Console.WriteLine("How many bags do you have?")
BagNumber = Console.ReadLine
If BagNumber = 3 Then
Console.WriteLine("Who is the first bag for?")
FirstBag = Console.ReadLine()
Console.WriteLine("Who is the second bag for?")
SecondBag = Console.ReadLine
Console.WriteLine("Who is the third bag for?")
ThirdBag = Console.ReadLine
Else
Console.WriteLine("That is not the correct amount of bags.")
End If
Else
Console.WriteLine("You have no wool.")
End If
**If (FirstBag = "master" & SecondBag = "dame" & ThirdBag = "little girl") Then
Console.WriteLine("You really know your nursery rhymes!")
End If**
**This is the part that doesn't work**
Console.ReadLine()
End Sub
End Module
最佳答案
您应该使用AndAlso
运算符比较您的值。If FirstBag = "master" AndAlso SecondBag = "dame" AndAlso ThirdBag = "little girl" Then
您可以使用普通的And
运算符来完成此操作,但是AndAlso
支持短路。
编辑:短路是一种编程结构,如果该语句的较早部分使检查该语句的其余部分变得毫无意义,则允许您跳过对多部分条件语句的各部分的求值。
示例:如果a == b AndAlso c == d
返回c == d
,则a == b
不会尝试评估false