|
|
|
Quality business correspondence.
|
|
|
|
ASP Loop Statements
Loops are set of instructions that repeat elements in specific number of times.
Counter variable is used to increment or decrement with each repetition of the loop.
Two major groups of loops are, For..Next and Do..Loop. While..Wend is another type of Do..Loop.
For statements are best used when you want to perform a loop in specific number of times.
Do and While statements are best used to perform a loop an undetermined number of times.
This is a For..Next example which counts from 1 to 5.
<%
Dim counter
counter=0
for counter = 0 to 5
response.write("The counter is: "&counter&"<br>")
next
%>
|
The above example increments a variable counter from 0 to 5, values of counter are incremented by 1 on each run before 6.
We can modified how the values are incremented by adding step # to
the for counter statement.
Here is For..Next example incrementing values by two.
<%
Dim counter
counter=0
for counter = 0 to 5 step 2
response.write("The counter is: "&counter&"<br>")
next
%>
|
The following example increments a variable counter from 5 to 0
The values are decremented by 1.
It's first example with reversed order.
<%
Dim counter
counter=0
for counter = 5 to 0 step -1
response.write("The counter is: "&counter&"<br>")
next
%>
|
Do Loop
Do..Loop structure repeats a block of statements until
a specified condition is met. There are three types of Do..Loops.
Do..Until, Do..While, and While..Wend.
Do..While and While..Wend performs a loop statement as long
as the condition being tested is true while
Do..Until performs a loop statement as long as the condition tested
is false. In both cases, you have a choice to
perform the test at start of the loop or at the end of the loop
This Do..Until loop example performs the test at the start of the loop:
<%
Dim counter
counter=5
Do
response.write("The counter is: "&counter&"<br>")
counter=counter-1
loop until counter =0
%>
|
You can also accomplish the loop this way:
<%
Dim counter
counter=5
Do Until counter=0
response.write("The counter is: "&counter&"<br>")
counter=counter-1
loop
%>
|
|
Case Statements
Form Processing
|
|
|