For i = 1 To 4 x = 4 For j = 1 To 3 x = 3 For k = 1 To 2 x = x + 6 Next k Next j Next i X=15?为什么
问题描述:
For i = 1 To 4 x = 4 For j = 1 To 3 x = 3 For k = 1 To 2 x = x + 6 Next k Next j Next i X=15?为什么
答
不要看最外层的循环
for i=1 to 4 当I=4时 x也是等于3
for j=1 to 3 当J=3时 x也是等于3
所以真正的循环为 for k=1 to 2
循环2次,第一次,x初值是3,执行x=x+6后x=9 第二次,x值是9,执行x=x+6后x=15也就是最后的结果