dim a(5)

问题描述:

dim a(5)
for i=1 to 5
a(i)=i
next
t=a(1)
for i =2 to 5
a(i-1)=i
next
a(i-1)=t
for i=1to5
print a(i)
next
结果是2-3-4-5-1为什么最后一个是1呢?

Dim a(5)
For i = 1 To 5
a(i) = i
Next
'此时,a(1)=1,a(2)=2,a(3)=3,a(4)=4,a(5)=5
t = a(1)
'此时,t=1
For i = 2 To 5
a(i - 1) = i
Next
'此时,a(1)=2,a(2)=3,a(3)=4,a(4)=5,a(5)未变化还是5
'此时i=6
a(i - 1) = t
'此时,a(i-1)=a(5)=t=1
For i = 1 To 5
Print a(i)
Next