萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp編程 >> asp For Next 循環語句語法與實例

asp For Next 循環語句語法與實例

For Next循環使用時,你要執行一段代碼多次集數。語法如下:
For counter = initial_value to  finite_value [Step increment]
  statements
Next
For語句指定計數器變量及其初步和有限的價值。 Next語句增加了對抗一個變量。可

選的步驟關鍵字允許增加或減少的值指定計數器變量。

有一個很簡單的例子:

<%@ language="vbscript" %>
<%
For i = 0 to 10 Step 2 'use i as a counter
 response.write("The number is " & i & "<br />")
Next
%>

復雜實例

Select ActionSelect AllTry It<%@ language="vbscript" %>
<%
response.write("<h1>Multiplication table</h1>")
response.write("<table border=2 width=50%")

For i = 1 to 9             'this is the outer loop
   response.write("<tr>")
   response.write("<td>" & i & "</td>")
 
   For j = 2 to 9          'inner loop
        response.write("<td>" & i * j & "</td>")
   Next 'repeat the code and move on to the next value of j 

   response.write("</tr>")
Next 'repeat the code and move on to the next value of i

response.write("</table>")
%>

copyright © 萬盛學電腦網 all rights reserved