for迴圈嵌套的時候一定要及時跳出,否則就會出現莫名其妙的問題,就像我開始的時候這樣:
寫一個線上購彩程式,當使用者在購彩頁面選擇了複選框的值後,程式會根據這些值產生可能的注數,並輸出。
for each b in iddI
for each c in iddII
for each d in iddIII
for each e in iddIV
for each f in iddV
for each g in iddVI
for each h in iddVII
'if b="" then
'response.write("資料位元數不完全,請您重新選擇")
'response.end()
'end if
if caizhong="福彩3D" or caizhong="排列3" then
n=trim(b)&trim(c)&trim(d)
str=str&n&" "
elseif caizhong="排列5" then
n=trim(b)&trim(c)&trim(d)&trim(e)&trim(f)
str=str&n&" "
elseif caizhong="七星彩" then
n=trim(b)&trim(c)&trim(d)&trim(e)&trim(f)&trim(g)&trim(h)
str=str&n&" "
end if
next
next
next
next
next
next
next
輸出時用的是
<%=str%>
奇怪的是只有當caizhong="七星彩"的時候才能正常輸出,其他情況下str的值都為空白。誰知道怎麼回事兒,給幫下忙。多謝了先。
到處求教而不得其解,鬱悶的我都快要撞牆了,最後查for迴圈的時候看到跳出迴圈的語句 exit for,靈感突發,心想,是不是沒有跳出迴圈的原因呢?修改程式為如下代碼:
for each b in iddI
for each c in iddII
for each d in iddIII
if caizhong="福彩3D" or caizhong="排列3" then
n=trim(b)&trim(c)&trim(d)
str=str&n&" "
exit for
end if
for each e in iddIV
for each f in iddV
if caizhong="排列5" then
n=trim(b)&trim(c)&trim(d)&trim(e)&trim(f)
str=str&n&" "
exit for
end if
for each g in iddVI
for each h in iddVII
if caizhong="七星彩" then
n=trim(b)&trim(c)&trim(d)&trim(e)&trim(f)&trim(g)&trim(h)
str=str&n&" "
end if
next
next
next
next
next
next
next
儲存,運行,哈哈終於按我的意思顯示了,激動ing。
大家以後再使用for迴圈嵌套的時候要小心嘍,該跳出的時候一定要跳出。