问题描述:
vb题目求教求结果
a=0:b=0
for c=-1 to -2 step -1
for d=1 to 2
b=b+1
next d
a=a+1
next c
print a;b
4
最佳答案:
For c = -1 To -2 Step -1
For d = 1 To 2
b = b + 1
Next d
a = a + 1
Next c
初始值 a = 0 , b = 0.
我们规定外层的 c 循环为大循环,内层的 d 循环为小循环.
【第一次大循环:c = -1】
进入小循环:
第一次:d = 1 , b = b + 1 = 0 + 1 = 1.
第二次:d = 2 , b = b + 1 = 1 + 1 = 2.
退出小循环:
a = a + 1 = 0 + 1 = 1.
【第二次大循环:c = -2】
进入小循环:
第一次:d = 1 , b = b + 1 = 2 + 1 = 3.
第二次:d = 2 , b = b + 1 = 3 + 1 = 4. ①
退出小循环:
a = a + 1 = 1 + 1 = 2. ②
由①②知 a = 2, b = 4.