Sub InsertionSort(ByRef intArray() As Integer)
Dim intIndex, intPreviousIndex, intTempItem As Integer
For intIndex = 1 To intArray.Length - 1
intTempItem = intArray(intIndex)
intPreviousIndex = intIndex - 1
Do While intPreviousIndex > 0
And intArray(intPreviousIndex) > intTempItem
intArray(intPreviousIndex + 1) = intArray(intPreviousIndex)
intPreviousIndex = intPreviousIndex - 1
Loop
If intArray(intPreviousIndex) > intTempItem Then
intArray(intPreviousIndex + 1) = intArray(intPreviousIndex)
intArray(intPreviousIndex) = intTempItem
End If
Next intIndex
End Sub
为什么我会收到错误“And”在哪里?错误是:
错误1语法错误。 H:\ Visual Studio 2012 \ Projects \ BubbleSort \ BubbleSort \ Form1.vb 48 13 BubbleSort
有谁知道为什么?
答案 0 :(得分:3)
因为隐式线路延续在And
之后,而不是之前。您可以将And
向上移动一行,也可以添加显式行继续(下划线 _ )。所以要么:
Do While intPreviousIndex > 0 And
intArray(intPreviousIndex) > intTempItem
或者这个:
Do While intPreviousIndex > 0 _
And intArray(intPreviousIndex) > intTempItem
应该有效。官方参考: