作业帮 > 综合 > 作业

程序算法里面的问题 for i =1 to 20 step 2 for j = i to 20 step 3

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/12 13:21:48
程序算法里面的问题 for i =1 to 20 step 2 for j = i to 20 step 3
private sub command1_click()
dim i,j,x
for i = 1 to 20 step 2
x=0
for j = i to 20 step 3
x=x+1
next j
next i
text1.value=str(x)
end sub
请问j到底是怎么执行的?
还有在这个步长什么的算法里,如果step后面数字是负的 到底能不能执行
程序算法里面的问题 for i =1 to 20 step 2 for j = i to 20 step 3
如果步长为负数,那么for i = 1 to 20,执行,但是死循环.
步长你可以理解为等差
譬如第一次i = 1,步长为2,那下一次就是i+2 = 3,下一次就是5,依此类推,明白了没有?
再问: 那我上面打出的这道题目呢?j= i to 20 step 3 i是个变量怎么办
再答: 你的是vb for i = 1 to 20 step 2 x=0 解释下当i=1的处理 for j = i to 20 step 3 --> j =1---> 20, step = 3 这里执行是从1到20,每次增加3, x=x+1 next j next i
再问: 那答案为什么是1? 我还是不太懂
再答: 我把每一次循环过程都给你写出来了,你分析下 i = 1, j =1, x = 1 i = 1, j =4, x = 2 i = 1, j =7, x = 3 i = 1, j =10, x = 4 i = 1, j =13, x = 5 i = 1, j =16, x = 6 i = 1, j =19, x = 7 i = 3, j =3, x = 1 i = 3, j =6, x = 2 i = 3, j =9, x = 3 i = 3, j =12, x = 4 i = 3, j =15, x = 5 i = 3, j =18, x = 6 i = 5, j =5, x = 1 i = 5, j =8, x = 2 i = 5, j =11, x = 3 i = 5, j =14, x = 4 i = 5, j =17, x = 5 i = 5, j =20, x = 6 i = 7, j =7, x = 1 i = 7, j =10, x = 2 i = 7, j =13, x = 3 i = 7, j =16, x = 4 i = 7, j =19, x = 5 i = 9, j =9, x = 1 i = 9, j =12, x = 2 i = 9, j =15, x = 3 i = 9, j =18, x = 4 i = 11, j =11, x = 1 i = 11, j =14, x = 2 i = 11, j =17, x = 3 i = 11, j =20, x = 4 i = 13, j =13, x = 1 i = 13, j =16, x = 2 i = 13, j =19, x = 3 i = 15, j =15, x = 1 i = 15, j =18, x = 2 i = 17, j =17, x = 1 i = 17, j =20, x = 2 i = 19, j =19, x = 1 1