我的問題是我不能不保持邏輯做雖然不是blFound和intCounter < intPoitns.Length bacause按順序做while while循環開始執行時兩個語句都必須是true所以如果不是blFound它是這意味着它是真的,但它分配給布爾值false,所以爲什麼循環執行,並且不僅適用於blFound或也適用於intCounter。它看起來很容易,但是如果有人能用非常簡單的語言解釋它的請求,那麼我的大腦就不會在同一時間處理它。感謝您的時間!VB和一般邏輯undarstanding
這裏是例子: 假設intValidNumbers是一個整數數組。編寫在數組中搜索值爲247的代碼。如果該值爲founf,則顯示消息它位於數組中。如果未找到,則顯示一條表示如此的消息
Dim intPoitns() As Integer = {11, 42, 322, 24, 247}
Dim strInput As String = InputBox("Enter integer", "Data needed")
Dim intInput As Integer
Dim blFound As Boolean = False
Dim intCounter As Integer = 0
Dim intPosition As Integer
If Integer.TryParse(strInput, intInput) Then
Do While Not blFound And intCounter < intPoitns.Length
If intPoitns(intCounter) = intInput Then
blFound = True
intPosition = intCounter
End If
intCounter += 1
Loop
Else
MessageBox.Show("have to enter integer number")
End If
If blFound Then
lblResult.Text = ("You found" & intPosition + 1)
Else
lblResult.Text = ("not Found")
End If
作爲一個側面說明,這樣寫這樣的行會更清晰(對於人的可讀性 - 編譯器不關心): Do While(not blFound)and(intCounter
peterG