如何理解VB中for循环语句嵌套
PrivateSubcmdArray_Click()Dimai(5,4)AsIntegerFora=0To5Fori=0To4ai(a,i)=a+iNextiNextaF...
Private Sub cmdArray_Click()
Dim ai(5, 4) As Integer
For a = 0 To 5
For i = 0 To 4
ai(a, i) = a + i
Next i
Next a
For a = 0 To 5
For i = 0 To 4
Print ai(a, i);
Next i
Print
Next a
End Sub
本人认为当for a=5的时候(从0开始,已经第6次循环),i这时候已经大于4,所以不会再执行
For i = 0 To 4
ai(a, i) = a + i
Next i
中的ai(a, i) = a + i
但打印结果最大数却等于9.请问如何理解该语句?谢谢! 展开
Dim ai(5, 4) As Integer
For a = 0 To 5
For i = 0 To 4
ai(a, i) = a + i
Next i
Next a
For a = 0 To 5
For i = 0 To 4
Print ai(a, i);
Next i
Next a
End Sub
本人认为当for a=5的时候(从0开始,已经第6次循环),i这时候已经大于4,所以不会再执行
For i = 0 To 4
ai(a, i) = a + i
Next i
中的ai(a, i) = a + i
但打印结果最大数却等于9.请问如何理解该语句?谢谢! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |