Você está na página 1de 6

VBScript Looping Statements

HOME VBScript Looping Statements


VBScript Tutorial Domain Name
VB HOME Registration & More!
VB Introduction WEB HOSTING
VB How to $15 Domain Name
VB Where to Registration
Examples
VB Variables Save $20 / year!
VB Procedures
For...next loop UK Domain Names
VB Conditional
This example demonstrates how to make a simple Web Hosting
VB Looping
For....Next loop. Merkaweb Dominios
Examples Buy UK Domain Names
VB Examples Looping through headers Register Domain Names
This example demonstrates how you can loop through
References the 6 headers in html. Website Hosting
VB Functions Domain Hosting
VB Keywords Web Hosting
For...each loop
This example demonstrates how to make a simple Cheap Domain Names UK
For.....Each loop. Domain Names UK
Quality Web Hosting
Do...While loop Webmail & POP3 Email
This example demonstrates how to make a simple
Web Hosting UK
Do...While loop.
Dedicated Servers UK
Domain Names UK
Business Web Hosting
Looping Statements Free Web Hosting
Cheap Web Hosting
Web Hosting Reseller
Very often when you write code, you want to allow the
same block of code to run a number of times. You can Website Design UK
use looping statements in your code to do this.
Reseller Hosting
HTML & Flash
In VBScript we have four looping statements:
Download HTML Editor
Flash Web Builder
For...Next statement - runs statements a Flash Templates
specified number of times.
For Each...Next statement - runs HOTELS
statements for each item in a collection or
each element of an array
Do...Loop statement - loops while or until a
condition is true
While...Wend statement - Do not use it -
use the Do...Loop statement instead

http://www.w3schools.com/vbscript/vbscript_looping.asp (1 of 6)4/15/2004 12:26:25 AM


VBScript Looping Statements

Amsterdam Hotels
For...Next Boston Hotels
Chicago Hotels
You can use a For...Next statement to run a block of London Hotels
code, when you know how many repetitions you want. Los Angeles Hotels
Miami Hotels
You can use a counter variable that increases or New York Hotels
decreases with each repetition of the loop, like this: New Orleans Hotels
Paris Hotels
For i=1 to 10 Rome Hotels
some code Hotel Reservations
Next Discount Hotels
Hotel Rooms

The For statement specifies the counter variable (i) Web Building
and its start and end values. The Next statement Website Templates
increases the counter variable (i) by one. Website Builder
Flash Templates
Step Keyword Web Templates
Shopping
Using the Step keyword, you can increase or decrease Discount Apparel
the counter variable by the value you specify. Online Coupons
Cooking tools
Men & women clothing
In the example below, the counter variable (i) is
increased by two each time the loop repeats. Office supply
Home Finance
For i=2 To 10 Step 2 Shopping UK
some code UK Wholesalers
Next
Mobile Phones
Direct TV
To decrease the counter variable, you must use a Plasma TV
negative Step value. You must specify an end value Prepaid Phones
that is less than the start value. 123 Fast Loans
Software
In the example below, the counter variable (i) is Meta Search Engine
decreased by two each time the loop repeats.
Your Own Web Site?

For i=10 To 2 Step -2 Read W3Schools


some code Hosting Tutorial
Next
WebDev Books

Exit a For...Next

You can exit a For...Next statement with the Exit For


keyword.

For Each...Next

A For Each...Next loop repeats a block of code for

http://www.w3schools.com/vbscript/vbscript_looping.asp (2 of 6)4/15/2004 12:26:25 AM


VBScript Looping Statements

each item in a collection, or for each element of an


Grow Your
array.
Web Design
Business!
The For Each...Next statement looks almost identical
to the For...Next statement. The difference is that you
do not have to specify the number of items you want Download
to loop through. a Sample

dim names(2) Learn CSS


names(0)="Tove" Positioning the
names(1)="Jani" easy way!
names(2)="Hege"
Download
For Each x in names a Sample
document.write(x & "<br />")
Next Learn PHP &
MySQL the easy
way!
Download
Do...Loop a Sample

You can use Do...Loop statements to run a block of


SELECTED LINKS
code when you do not know how many repetitions you
University Online
want. The block of code is repeated while a condition is
true or until a condition becomes true. Master Degree
Bachelor Degree

Repeating Code While a Condition is True Web Security


Web Statistics
You use the While keyword to check a condition in a Web Standards
Do...Loop statement.
Web Quality

Do While i>10
some code
Loop

If i equals 9, the code inside the loop above will never


be executed.

Do
some code
Loop While i>10

The code inside this loop will be executed at least one


time, even if i is less than 10.

Repeating Code Until a Condition Becomes


True

You use the Until keyword to check a condition in a


Do...Loop statement.

http://www.w3schools.com/vbscript/vbscript_looping.asp (3 of 6)4/15/2004 12:26:25 AM


VBScript Looping Statements

Do Until i=10
some code
Loop

If i equals 10, the code inside the loop will never be


executed.

Do
some code
Loop Until i=10

The code inside this loop will be executed at least one


time, even if i is equal to 10.

Exit a Do...Loop

You can exit a Do...Loop statement with the Exit Do


keyword.

Do Until i=10
i=i-1
If i<10 Then Exit Do
Loop

The code inside this loop will be executed as long as i


is different from 10, and as long as i is greater than
10.

Product Spotlight

AspUpload:
Advanced file upload solution. Provides a progress bar,
encryption, Unicode support.

Want To Be A Web Master?

If you want to be a Web Master, you will have to host


your web site with an ISP (Internet Service Provider).

Maximum ASP is a service provider with a unique web


hosting platform designed specifically for serious
Microsoft developers. They offer high performance and
stability at a good price with a 30-day, money-back
guarantee.

http://www.w3schools.com/vbscript/vbscript_looping.asp (4 of 6)4/15/2004 12:26:25 AM


VBScript Looping Statements

They have access to all of Microsoft's web


technologies, and their support staff are 100%
Microsoft-certified.

Visit MaximumASP

The Web Design Business Kit

Brendon Sinclair has a unique philosophy that


everyone from Freelancers to the huge International
Web Design Shops can learn from:

Your Web
Design and
Development
skills don't
matter!
You don't have
to be the
cheapest bidder
to win!
Charging by
the hour is the
worst thing you
can do!
Your clients are
everywhere!
When the
project
finishes, your
income should
not!

Want to know more...?

Receive 4 FREE
CHAPTERS in your
inbox:
http://www.sitepoint.
com/launch/3a9053/2/4

or read more:
http://www.sitepoint.
com/launch/3a9053/3/4

We Help You For Free. You Can Help Us!

Make a small donation


Tell your newsgroup or mailing list
Link to us from your pages

http://www.w3schools.com/vbscript/vbscript_looping.asp (5 of 6)4/15/2004 12:26:25 AM


VBScript Looping Statements

Help us correct errors and broken links


Help us with spelling and grammar
Validate the XHTML code of this page

Jump to: Top of Page or HOME or Printer


friendly page

Search W3Schools:

Go!

What Others Say About Us

Does the world know about us? Check out these places:

Google Yahoo Alta Vista MSN Lycos Excite Ask


Jeeves HotBot

W3Schools is for training only. We do not warrant the


correctness of the content. The risk of using it remains
entirely with the user. While using this site, you agree
to have read and accepted our terms of use and
privacy policy.

Copyright 1999-2004 by Refsnes Data. All Rights


Reserved.

How W3Schools
was converted to
XHTML

http://www.w3schools.com/vbscript/vbscript_looping.asp (6 of 6)4/15/2004 12:26:25 AM

Você também pode gostar