中易网

ASP简单代码问题

答案:3  悬赏:40  
解决时间 2021-04-28 00:29
  • 提问者网友:花之森
  • 2021-04-27 17:27

Dim a(6)

for i=0 to 6

a(i)=i+1

next

for i=0 to 6

count=count+a(i)+1

next

response.write count

谁能帮我详细的解释下代码,最后输出的结果又是什么

最佳答案
  • 二级知识专家网友:走,耍流氓去
  • 2021-04-27 18:11

<%
Dim a(6)'数组,从a(0)-a(7)


for i=0 to 6'循环7次


a(i)=i+1
'给数组赋值,运行过程
'第一次循环,a(1)=1+1=2
'第二次循环,a(2)=2+1=3
'第三次循环,a(3)=3+1=4
'第四次循环,a(4)=4+1=5
'第五次循环,a(5)=5+1=6
'第六次循环,a(6)=6+1=7
'第七次循环,a(7)=7+1=8


next


'利用循环非别给a(0)-a(7)赋了值


for i=0 to 6'又一个循环,也是7次


count=count+a(i)+1
'变量count默认为0,运行过程
'count=0+2+1=3
'count=0+3+1=4
'count=0+4+1=5
'count=0+5+1=6
'count=0+6+1=7
'count=0+7+1=8
'count=0+8+1=9


next
'最后变量count的值为9
response.write count


%>

全部回答
  • 1楼网友:ー何必说爱
  • 2021-04-27 19:05

Dim a(6)//定义一个6位数组

for i=0 to 6

a(i)=i+1 //利用循环给数组赋值 a(0)=1、a(1)=2、a(2)=3、a(3)=4、a(4)=5、a(5)=6

next

for i=0 to 6

count=count+a(i)+1 //利用循环计算数组的和+6

next

response.write count//输出结果27

  • 2楼网友:木子香沫兮
  • 2021-04-27 18:19

Dim a(6) '声明数组

for i=0 to 6 'FOR语句,循环从0到6目的是便利数组

a(i)=i+1 '对数组每个对象赋值

next 'FOR结束

for i=0 to 6 'FOR语句,循环从0到6目的是对变量count进行累加

count=count+a(i)+1 '变量count的累加,其中a(i)是取得数组中的值

next 'FOR结束

response.write count '输出

结果:35

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息