单选题
VB
题号 #5100638
设有以下程序代码:
上面事件过程执行后产生的输出是( )。
参考答案
D
答案解析
程序中变量a和变量b分别为数组变量,并且使用Array函数给两个数组进行了初始化,变量i和j初始值均为0,程序进入Do……Loop Until循环结构,程序执行过程如下所示:
第一次循环,变量i=0,j.0,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(j)条件为真,执行语句print a(i),i=i+1输出1,变量i的值为1;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为假,继续执行循环。
第二次循环,变量i=1,J=0,ifi<=UBound(A.andj(=UBound(B.条件为真,执行判断语句if a(i)<b(j)条件为真,执行语句print a(i),i=i+1输出2,变量i的值为2;执行循环判断语句i>UBound(A.And j>UBound(B.,条件为假,继续执行循环。
第三次循环,变量i=2,j=0,ifi<=UBound(A.and J<=UBound(B.条件为真,执行判断语句if a(i)<b(J)条件为假,执行语句Print b(J),j=J+1输出5,变量j的值为1;执行循环判断语句i>UBound(A.And j>UBound(B.,条件为假,继续执行循环。
第四次循环,变量i=2,j=1,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(J)条件为假,执行语句Print b(j),j=j+1输出4,变量j的值为2;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为假,继续执行循环。
第五次循环,变量i=2,j=2,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(J)条件为假,执行语句Print b(j),j=j+1输出7,变量j的值为3;执行循环判断语句i>UBound(A.And j>UBound(B.,条件为假,继续执行循环。
第六次循环,变量i=2,j-3,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(J)条件为真,执行语句print a(i),i=i+1输出7,变量i的值为3;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为假,继续执行循环。
第七次循环,变量i=3,j=3,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(j)条件为假,执行语句Print b(J),j=j+1输出8,变量J的值为4;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为假,继续执行循环。
第八次循环,变量i=3,j=4,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(j)条件为假,执行语句Print b(j),j=J+1输出2,变量J的值为5;执行循环判断语句i>UBound(A.And j>UBound(B.,条件为假,继续执行循环。
第九次循环,变量i=3,j=5,ifi<=UBound(A.and J<=UBound(B.条件为假,执行判断语句If i<=UBound(A.条件为真,执行语句print a(i),i=i+1输出l0,变量i的值为4;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为假,继续执行循环。
第十次循环,变量i=4,j=5,ifi<=UBound(A.andj<=UBound(B.条件为假,执行判断语句If i<=UBound(A.条件为真,执行语句print a(i),i=i+1输出6,变量i的值为5;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为真,循环结束。
所以程序输出的结果为1、2、 5、 4、 7、 7、 8、 2、 10 、6,D选项正确。本题选择D选项。
第一次循环,变量i=0,j.0,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(j)条件为真,执行语句print a(i),i=i+1输出1,变量i的值为1;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为假,继续执行循环。
第二次循环,变量i=1,J=0,ifi<=UBound(A.andj(=UBound(B.条件为真,执行判断语句if a(i)<b(j)条件为真,执行语句print a(i),i=i+1输出2,变量i的值为2;执行循环判断语句i>UBound(A.And j>UBound(B.,条件为假,继续执行循环。
第三次循环,变量i=2,j=0,ifi<=UBound(A.and J<=UBound(B.条件为真,执行判断语句if a(i)<b(J)条件为假,执行语句Print b(J),j=J+1输出5,变量j的值为1;执行循环判断语句i>UBound(A.And j>UBound(B.,条件为假,继续执行循环。
第四次循环,变量i=2,j=1,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(J)条件为假,执行语句Print b(j),j=j+1输出4,变量j的值为2;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为假,继续执行循环。
第五次循环,变量i=2,j=2,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(J)条件为假,执行语句Print b(j),j=j+1输出7,变量j的值为3;执行循环判断语句i>UBound(A.And j>UBound(B.,条件为假,继续执行循环。
第六次循环,变量i=2,j-3,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(J)条件为真,执行语句print a(i),i=i+1输出7,变量i的值为3;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为假,继续执行循环。
第七次循环,变量i=3,j=3,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(j)条件为假,执行语句Print b(J),j=j+1输出8,变量J的值为4;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为假,继续执行循环。
第八次循环,变量i=3,j=4,ifi<=UBound(A.andj<=UBound(B.条件为真,执行判断语句if a(i)<b(j)条件为假,执行语句Print b(j),j=J+1输出2,变量J的值为5;执行循环判断语句i>UBound(A.And j>UBound(B.,条件为假,继续执行循环。
第九次循环,变量i=3,j=5,ifi<=UBound(A.and J<=UBound(B.条件为假,执行判断语句If i<=UBound(A.条件为真,执行语句print a(i),i=i+1输出l0,变量i的值为4;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为假,继续执行循环。
第十次循环,变量i=4,j=5,ifi<=UBound(A.andj<=UBound(B.条件为假,执行判断语句If i<=UBound(A.条件为真,执行语句print a(i),i=i+1输出6,变量i的值为5;执行循环判断语句i>UBound(A.And J>UBound(B.,条件为真,循环结束。
所以程序输出的结果为1、2、 5、 4、 7、 7、 8、 2、 10 、6,D选项正确。本题选择D选项。