<html>
<%
dim shtx,shty as short
for shtx=1 to 2 step 1
for shty =1 to 2 step 1
response.write("shtx=" & cstr(shtx))
response.write(" shty=" & cstr(shty) & "<br>")
next
next shtx
%>
</html>

我们观察外层循环以及内层循环计数器的状态值便可知道,外层循环跳进内层循环执行时,外层等到内层执行完毕后再跳至外层将计数器加一,而每次跳进内层时内层计数器的值都会被重新设定。内层的循环会一直反复重新执行,直到外层超过结束值为止。接下来的例子我们利用巢状循环画出九九表:
<html>
<table border="1">
<%
dim shtx,shty as short
for shtx=1 to 9 step 1
if shtx=1 or shtx=4 or shtx=7 then response.write("<tr>")
response.write("<td>")
for shty =1 to 9 step 1
response.write(cstr(shtx) & "x" & cstr(shty) & "=" & _
cstr(shtx * shty) & "<br>")
next shty
response.write("</td>")
if shtx=3 or shtx=6 or shtx=9 then response.write("</tr>")
next shtx
%>
</table>
| 对此文章发表了评论 |

