Do Loop in VB.net
By: Ramlak Printer Friendly Format
The Do loop keeps executing its enclosed statements while or until (depending on which keyword you use, While or Until) condition is true. You can also terminate a Do loop at any time with an Exit Do statement. The Do loop has two versions; you can either evaluate a condition at the beginning:
Do [{While | Until} condition ] [statements] [Exit Do] [statements] Loop
or at the end:
Do [statements] [Exit Do] [statements] Loop [{While | Until} condition]
Here's an example where the code keeps displaying the message "What should I do?" until the user types "Stop" (note that I'm using UCase to uppercase what the user types and comparing it to "STOP" to let them use any combination of case when they type "Stop"):
Module Module1 Sub Main() Dim strInput As String Do Until UCase(strInput) = "STOP" System.Console.WriteLine("What should I do?") strInput = System.Console.ReadLine() Loop End Sub End Module
Tip |
The second form of the Do loop insures that the body of the loop is executed at least once. |
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Subscribe to Tutorials
Related Tutorials
Unstructured Exception Handling in VB.net
Structured Exception Handling in VB.net
Creating Sub Procedures in VB.net
Passing a Variable Number of Arguments to Procedures in VB.net
Specifying Optional Arguments with default values in Procedures in VB.net
Preserving a Variable's Values between Procedure Calls in VB.net
Using Resume Next and Resume Line in VB.net
Using On Error GoTo 0 in VB.net
Archived Comments
1. how can i combine do-loop statement on other state
View Tutorial By: hime at 2010-07-09 04:20:05
2. dsgfdhgjykllk;
View Tutorial By: surya at 2010-10-20 23:24:57