asp for循环

来源:百度知道 编辑:UC知道 时间:2024/05/26 18:51:39
<%
application.Lock
smgg=application("smg")
txx=application("tx")
if txx>9 then
txx=0
end if
smgg(txx)=session("name")&":"&request.Form("talk")
txx=txx+1
application("smg")=smgg
application("tx")=txx
application.UnLock
%>
<%
if application("tx")=0 then
temp=application("smg")(0)
else
for x=0 to application("tx")-1 '<---这里为什么要减1
temp=temp&"<br>"&application("smg")(x)
next
end if
response.Write temp
%>

for x=0 to application("tx")-1
这个for循环为什么要减1?

application("tx")存放的是application("smg")(x)
的总长度.
举个例子吧,比如说数组a[10]的话,长度为10,那么遍历a[i]的话
for i = 0 to 9 '这时9就是10-1.
response.write(a[i])
next
VB里面数组下标是从0开始到长度-1