- ASP.NET Web Pages - Tutorial
- ASP.NET Web Pages - Adding Razor Code
- ASP.NET Web Pages - Page Layout
- ASP.NET Web Pages - Folders
- ASP.NET Web Pages - Global Pages
- ASP.NET Web Pages - HTML Forms
- ASP.NET Web Pages - Objects
- ASP.NET Web Pages - Files
- ASP.NET Web Pages - Databases
- ASP.NET Web Pages - Helpers
- ASP.NET Web Pages - The WebGrid Helper
- ASP.NET Web Pages - The Chart Helper
- ASP.NET Web Pages - The WebMail Helper
- ASP.NET Web Pages - WebSecurity Object
- ASP.NET Web Pages - Publishing The Website
- ASP.NET Web Pages - Classes
- ASP.NET Razor - Markup
- ASP.NET Razor - C# And VB Code Syntax
- ASP.NET Razor - C# Variables
- ASP.NET Razor - C# Loops And Arrays
- ASP.NET Razor - C# Logic Conditions
- ASP.NET Razor - VB Variables
- ASP.NET Razor - VB Loops And Arrays
- ASP.NET Razor - VB Logic Conditions
- ASP Tutorial
- ASP Syntax
- ASP Variables
- ASP Procedures
- VBScript Conditional Statements
- VBScript Looping
- ASP Forms And User Input
- ASP Cookies
- ASP Session Object
- ASP Application Object
- ASP Including Files
- ASP The Global.asa File
- ASP AJAX
- ASP Sending E-mail With CDOSYS
- VBScript Functions
- VBScript Keywords
- ASP Response Object
- ASP Application Object
- ASP Session Object
- ASP Server Object
- ASP ASPError Object
- ASP FileSystemObject Object
- ASP TextStream Object
- ASP Drive Object
- ASP File Object
- ASP Folder Object
- ASP Dictionary Object
- ASP AdRotator Component
- ASP Browser Capabilities Component
- ASP Content Linking Component
- ASP Content Rotator Component (ASP 3.0)
- ASP Quick Reference
- ADO Introduction
- ADO Database Connection
- ADO Recordset
- ADO Display
- ADO Queries
- ADO Sort
- ADO Add Records
- ADO Update Records
- ADO Delete Records
- ADO Demonstration
- ADO Speed Up With GetString()
- ADO Command Object
- ADO Connection Object
- ADO Error Object
- ADO Field Object
- ADO Parameter Object
- ADO Property Object
- ADO Record Object
- ADO Recordset Object
- ADO Stream Object
- ADO Data Types
VBScript Looping
VBScript Looping
Looping statements are used to run the same block of code a specified number of times.
In VBScript we have four looping statements:
- For...Next statement - runs code a specified number of times
- For Each...Next statement - runs code 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
Practice Excercise Practice now
For...Next Loop
Use the For...Next statement to run a block of code a specified number of times.
The For statement specifies the counter variable (i), and its start and end values. The Next statement increases the counter variable (i) by one.
Example
<body>
<%
For i = 0 To 5
response.write("The number is " & i & "<br />")
Next
%>
</body>
</html>
Practice Excercise Practice now
The Step Keyword
With the Step keyword, you can increase or decrease the counter variable by the value you specify.
In the example below, the counter variable (i) is INCREASED by two, each time the loop repeats.
some code
Next
To decrease the counter variable, you must use a negative Step value. You must specify an end value that is less than the start value.
In the example below, the counter variable (i) is DECREASED by two, each time the loop repeats.
some code
Next
Exit a For...Next
You can exit a For...Next statement with the Exit For keyword.
If i=5 Then Exit For
some code
Next
Practice Excercise Practice now
For Each...Next Loop
A For Each...Next loop repeats a block of code for each item in a collection, or for each element of an array.
Example
<body>
<%
Dim cars(2)
cars(0)="Volvo"
cars(1)="Saab"
cars(2)="BMW"
For Each x In cars
response.write(x & "<br />")
Next
%>
</body>
</html>
Practice Excercise Practice now
Do...Loop
If you don't know how many repetitions you want, use a Do...Loop statement.
The Do...Loop statement repeats a block of code while a condition is true, or until a condition becomes true.
Repeat Code While a Condition is True
You use the While keyword to check a condition in a Do...Loop statement.
some code
Loop
If i equals 9, the code inside the loop above will never be executed.
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.
Repeat Code Until a Condition Becomes True
You use the Until keyword to check a condition in a Do...Loop statement.
some code
Loop
If i equals 10, the code inside the loop will never be executed.
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.
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.
Practice Excercise Practice now
Products
Partner
Copyright © RVR Innovations LLP 2025 | All rights reserved - Mytat.co is the venture of RVR Innovations LLP