ASP Junction Home Of EZCodes
20 visitors online
219721 total visitors

Sunday, 5 February, 2012
Home Downloads Articles Programming Portfolio Support Privacy  




Newsletter


The HTMLJunction Store

Top 5 Downloads
EZNewsletter: 12047
EZGallery: 7327
EZPoll: 7241
EZUpload: 6594
EZGuestbook: 6520
Download Stats
EZHomepagePro: 3923
EZHomepageBasic: 1573
EZNewsletter: 12047
EZOnlineEditor: 4541
EZMedia: 4250
EZGuestbook: 6520
EZGallery: 7327
EZPoll: 7241
EZScheduler: 3083
EZUpload: 6594
Total: 57944
HTMLJunction News
ASP Article - Dynamic Date Dropdown Menu.

ASP Article - Import Text File to an Access Database.

EZScheduler now available for download!

ASP Junction has just been launched!

HTMLJunction has a new store!


Advertisements






HTMLJunction is against any kind of spyware!




ASP Article
Rated out of 5 stars (5) - 1 Total Votes Submit Your ASP Article

For...Next Looping.



This article will explain how to use "For...Next" and "For Each...Next" Looping!

There are times when looping with For..Next comes in handy, like populating a dropdown menu dynamically or setting a boolean depending on if an item is in an array or collection. You can step through an Array or collection with the For..Next loop. We will cover the basics here

About the Author

Steve Frazier has been a classic ASP developer for about four years. He has developed ASP applications for Fortune 500 companies and popular websites. He has also developed many ASP Scripts of his own! He is Webmaster of HTMLJunction as well as its sister sites. The HTMLJunction Store - ASP Junction. He is currentlly working on a Web Portal that has the functionalities of all the most popular Forums and Portals.



Lets say you want to add a number to the end of a string then we can do this

<%
Dim i
For i = 1 to 10
  Response.Write "image"&i&"<br />"
Next
%>


If we run the code we get this:

image1
image2
image3
image4
image5
image6
image7
image8
image9
image10


If you only want to add even numbers to the string then we can use the Step method:

<%
Dim i
For i = 2 to 10 Step 2
  Response.Write "image"&i&"<br />"
Next
%>


To get this:

image2
image4
image6
image8
image10


If you have an Array or collection you can loop through it using the For Each...Next Loop:

<%
Dim x
Dim colors(2)

colors(0)="Red"
colors(1)="White"
colors(2)="Blue"

For Each x in colors
  Response.Write x&"<br />"
Next
%>


Gives us this:

Red
White
Blue


We can check to see if a certain item is in the Array and print only that item:

<%
Dim x
Dim names(2)

names(0)="Steve"
names(1)="Jay"
names(2)="Felicia"

For Each x in names
  If x = "Jay" Then
    Response.Write x
    Exit For
  End If
Next
%>


Gives us this:

Jay

There is a lot you can do with For...Next looping and I encourage you to play around with it!

Rate this Article
Good  
5 4 3 2 1
  Poor

Advertisements








We use Google Sitemaps to inform Google's crawler about all your pages and to help people discover more of your web pages.

Advertisements






Resources

Gunners Gallery
Wesley Ford
seo-advantage.com

copyright © 2012 ASP Junction
An HTMLJunction website