无效next引用变量

来源:百度知道 编辑:UC知道 时间:2024/06/12 08:20:27
Private Sub Command1_Click()
Dim a, b, c, d, e, f, n As Integer
n = 0
For a = 0 To 20
For b = 0 To 33
For c = 0 To 100
d = a * 5
e = b * 3
f = c / 3
If a + b + c = 100 And c Mod 3 = 0 And d + e + f = 100 Then
n = n + 1
Text1.Text = Str(n)
End If
Next a
Next b
Next c

End Sub
无效next引用变量

Private Sub Command1_Click()
Dim a, b, c, d, e, f, n As Integer
n = 0
For a = 0 To 20
For b = 0 To 33
For c = 0 To 100
d = a * 5
e = b * 3
f = c / 3
If a + b + c = 100 And c Mod 3 = 0 And d + e + f = 100 Then
n = n + 1
Text1.Text = Str(n)
End If
Next c
Next b
Next a
End Sub

循环应该是这样

For a = 0 To 20
For b = 0 To 33
For c = 0 To 100
...
Next c
Next b
Next a

Next a
Next b
Next c
顺序写反了,应该
Next c
Next b
Next a

for循环只能嵌套不能交叉,所以三个next的顺序应该是
next c
next b
next a
或者干脆省略next后的变量名,vb自己知道应该对应哪个

next c,b,a
或者你next next next也行