ASP Junction Home Of EZCodes
13 visitors online
84499 total visitors

Tuesday, 2 December, 2008
Home Downloads Articles Programming Portfolio Support  




Newsletter


The HTMLJunction Store

Top 5 Downloads
EZNewsletter: 9962
EZGallery: 5314
EZPoll: 5095
EZUpload: 4374
EZGuestbook: 3599
Download Stats
EZHomepagePro: 2953
EZHomepageBasic: 1573
EZNewsletter: 9962
EZOnlineEditor: 3266
EZMedia: 3089
EZGuestbook: 3599
EZGallery: 5314
EZPoll: 5095
EZScheduler: 1622
EZUpload: 4374
Total: 41159
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 - 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 © 2008 ASP Junction
An HTMLJunction website