VB x=0 for i =0 to 4,for j =0 to i-1,x=x+(i+j-1),exit for next j,next i,print x.

问题描述:

VB x=0 for i =0 to 4,for j =0 to i-1,x=x+(i+j-1),exit for next j,next i,print x.

x=0
for i =0 to 4
for j =0 to i-1
x=x+(i+j-1)
exit for
next j
next i
print x
内循环for j=0 to i-1,由于每次当j=0运行后都有个exit for,所以每次只运行了j=0,x=x+i+0-1,就是每次累加了i的值再减去1,i=4时,共累加了x=0-1+1-1+2-1+3-1+4-1=1+2+3+4-4=6