回 帖 发 新 帖 刷新版面

主题:初学者,令人费解的脚本

<html>
<head>
<title>select !</title>
</head>
<script language="vbscript">
option explicit
<!--
  sub doloop()
    dim c,sum
     c=sum=0
    do while c<101
     c=c+1
     sum=sum+c
     if c=myform.txt.value then
         exit do
     end if
    loop
    msgbox "1+2+3+ ... +"&amp;c&amp;"="&amp;sum
  end sub
-->
</script>
<body>
<form name="myform">
enter:  <input type="text" name="txt" size=20>

    <input type="button" onClick="doloop()" value="get sum">
</form>
</body>
</html>
如入 1 结果不是 1 而是 2
结论: c=sum=0 c != 0 而是 1请大家注意,尤其是 学过c语言的朋友

回复列表 (共1个回复)

沙发

这个好像是算100以内的任意自然数n,从1加到n的程序!因为超过100就不能用了。

我来回复

您尚未登录,请登录后再回复。点此登录或注册