为毛loop 语句缺少do?Dim d(1 To 15) As DoubleDim i As DoubleDim flag As DoubleDim key As DoubleDim m As Doubled(1) = 0d(2) = 2d(3) = 3d(4) = 6d(5) = 7d(6) = 9d(7) = 11d(8) = 12d(9) = 13d(10) = 15d(11) = 18d(12) = 19d(13) = 20d(14) = 24d(15) = 25
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 21:30:23
为毛loop 语句缺少do?Dim d(1 To 15) As DoubleDim i As DoubleDim flag As DoubleDim key As DoubleDim m As Doubled(1) = 0d(2) = 2d(3) = 3d(4) = 6d(5) = 7d(6) = 9d(7) = 11d(8) = 12d(9) = 13d(10) = 15d(11) = 18d(12) = 19d(13) = 20d(14) = 24d(15) = 25
为毛loop 语句缺少do?
Dim d(1 To 15) As Double
Dim i As Double
Dim flag As Double
Dim key As Double
Dim m As Double
d(1) = 0
d(2) = 2
d(3) = 3
d(4) = 6
d(5) = 7
d(6) = 9
d(7) = 11
d(8) = 12
d(9) = 13
d(10) = 15
d(11) = 18
d(12) = 19
d(13) = 20
d(14) = 24
d(15) = 25
key = InputBox("请输入一个数呦~")
i = 1
j = 15
flag = 0
Do While i <= j And flag = 0
m = Int(i + j) / 2
If d(m) = key Then
flag = m
Else
If d(m) < key Then
i = m + 1
Else
j = m - 1
End If
i = i + 1
Loop
If flag = 0 Then
Print "没有找到呦~"
Else
Print flag
End If
为什么就是不对啊~要哭了~
为毛loop 语句缺少do?Dim d(1 To 15) As DoubleDim i As DoubleDim flag As DoubleDim key As DoubleDim m As Doubled(1) = 0d(2) = 2d(3) = 3d(4) = 6d(5) = 7d(6) = 9d(7) = 11d(8) = 12d(9) = 13d(10) = 15d(11) = 18d(12) = 19d(13) = 20d(14) = 24d(15) = 25
do loop中有两个if,但就一个end if.
你应该这么写:
If condition Then[statements]
[ElseIf condition-n Then
[elseifstatements] ...
[Else
[elsestatements]]
End If
或者,if condition then [statements] 写到一行内,就不需要end if了