ASP Tutorial Lesson 8: Loops

Looping is an important part of programming. It allows you to perform the same operation over and over.

Following are the main loops used in ASP.

For .. Next

This loop will be familiar to anyone who has done basic programming. With this loop you can iterate a specified number of times while setting a variable to the current loop number. In the following example the code between the for and next statements would execute ten times, and would set x to be the current loop number from 1 to 10.

For x=1 to 10

next x

For each

This loop runs code for each item in a collection, setting a variable to contain the value of the current item in the collection.

For each item in array


Do .. while

This loop will iterate while the condition is met, so it is kind of like a mixture of an “if” and a loop.

do while [not] x<=>y



Questions on loops? You can always find great illustrations, tutorials, and helpful hints at