vb题目求教求结果a=0:b=0for c=-1 to -2 step -1for d=1 to 2b=b+1 next

1个回答

  • 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.