vb简单计算for a =1 to 2 for b =1 to a for c = b to 2 i=i+1 next nextnext print i答案i的值为什么是5而不是6?

来源:学生作业学帮网 编辑:学帮网 时间:2024/05/17 00:02:15

vb简单计算
for a =1 to 2
for b =1 to a
for c = b to 2
i=i+1
next
next
next
print i
答案i的值为什么是5而不是6?


当a=1时,b=1 to 1 ,c=1 to 2 所以这里 i 就加了两次,i=2


当a=2时,b=1 to 2,当b=1时 ,c=1 to 2 所以这里 i 也加了两次,i=4

                                 当b=2时, c=2 to 2 所以这里 i 只加了一次,i=5


这样即循环完,所以i=5