我初学自己编的这个函数有什么错误???帮我看看,我看不出来!

来源:百度知道 编辑:UC知道 时间:2024/05/18 18:08:15
<%
function sum(n)
dim i
for i=1 to n
i=i+1
next
end function
s=100
response.Write("这是一个从1加到"&s&"的运算其结果是"&sum(s))
%>
这个ASP函数为什么不能实现。
这应该是对的啊,看这for循环这里“i”一始是1,一个循环后“i=i+1”
i为2后一直循环如此到100!
代入函数sum(s)
不是对的吗??
怎么没有效果??,
请各位武林大侠,美女帮帮我。
先在这里谢谢了

function sum(n)
dim i,total
for i=1 to n
total= total+ i; //你这里写错了.
next
sum=total //还有,你的函数没有返回值.我帮你加上
end function

问题的关键是你没有返回值
i=i+1
然后返回i

靠,你不要用SUM做为函数名就可以了!~~

GOOD LUCK!~~~

你这是用哪个语言编的?

i=i+1

这个错了。

你可能随意再设个变量,把i替换掉。

如M=M+1

function sum(n)
dim i
for i =1 to n
i=i+1
next
end function

s=sum(100)
response.write("……"&s)