asp中的循环语句

   在asp中,循环主要有以下几种(脚本语言为vbscript):
   1、do......1oop循环
    有两种:
    第一,“当型”do......lloop循环
    又分为两类:
    do while (条件语句)
    执行语句
    exit do
    loop
 示例:
  
<%
counter = 1
thismonth = month(now())
Do while counter < thismonth + 1
response.write  (counter & " 月份 : ")
response.write ("______________________________" & "<br><br>")
If counter >13 then
exit do
end if
counter = counter+1
Loop
%>


    do 
    执行语句
    exit do
    loop while 条件语句
  示例:
<%
counter = 1
thismonth = month(now())
Do
response.write  (counter & " 月份 : ")
response.write ("______________________________" & "<br><br>")
If counter >13 then
exit do
end if
counter = counter+1
Loop while counter < thismonth + 1
%>


    第二,“直到型”do......lloop循环
     do until 条件语句
     exit do
     loop
   实例:
 
<%
counter = 1
thismonth = month(now())
Do until counter=thismonth
response.write  (counter & " 月份 : ")
response.write ("______________________________" & "<br><br>")
If counter >13 then
exit do
end if
counter = counter+1
Loop
%>

2、for循环
分为两种:
第一、for .....next 循环
例如:
dim i=0
dim sum=0
for i=1 to 10
sum=sum+i
next 
第二,for each ......next 
说明:For Each...Next: 对于集合中的每项或数组中的每个元素,重复执行一组语句。For Each...Next 循环与 For...Next 循环类似。For Each...Next 不是将语句运行指定的次数,而是对于数组中的每个元素或对象集合中的每一项重复一组语句。这在不知道集合中元素的数目时非常有用。它的语法如下: For Each element In group
[statements]
Exit For
[statements]Next [element]
如果 group 中有至少一个元素,就会进入 For Each 块执行。一旦进入循环,便首先对 group 中第一个元素执行循环中的所有语句。只要 group 中还有其他的元素,就会对每个元素执行循环中的语句。当 group 中没有其他元素时退出循环,然后从 Next 语句之后的语句继续执行。
  

posted on 2008-06-10 11:15  阿良  阅读(2840)  评论(0编辑  收藏  举报