While Loop in VB.net
By Ramlak Viewed: 31811 times Emailed: 198 times Printed: 192 times
While loops keep looping while the condition they test remains true, so you use a While loop if you have a condition that will become false when you want to stop looping. Here's the While loop's syntax (note that you used to end this loop with Wend in VB6 and before—that's changed to End While now):
While condition
[statements]
End While
And here's an example putting While to work:
Sub CheckWhile() Dim intCounter As Integer = 0 Dim intNumber As Integer = 10 While intNumber > 6 intNumber -= 1 intCounter += 1 End While MsgBox("The loop ran " & intCounter & " times.") End Sub
And here's what you see when you run this code:
The loop ran 4 times. Press any key to continue
| Tip |
Many Visual Basic functions, like EOF—which is true when you've reached the end of a file while reading from it—are explicitly constructed to return values of True or False so that you can use them to control loops such as Do and While loops. |
Comments(0)
Be the first one to add a comment
Latest Tutorials
| [2009-03-22] | Handling Timer Events - and Creating an Alarm Clock in VB.net |
| [2009-03-22] | Creating Menus in Code using VB.net |
| [2009-03-22] | Creating Context Menus in Code using VB.net |
| [2009-03-22] | Creating Tree Views in Code using VB.net |
| [2009-03-22] | Creating List Views in Code using VB.net |
| [2009-03-16] | Send SMS using VB code |
| [2009-02-27] | Creating a Windows Service in VB.net |
| [2009-02-27] | Creating a Windows Service Installer in VB.net |
| [2009-02-24] | OleDbConnection class in VB.net |
| [2009-02-24] | OleDbDataAdapter class in VB.net |
| [2009-02-24] | DataSet Class in VB.net |
| [2009-02-24] | DataTable Class in VB.net |
| [2009-02-24] | DataRow Class in VB.net |
| [2009-02-22] | Chat Server in VB.net |
| [2009-02-22] | A tutorial on Chat Server and Chat Client in VB.net |
Most Viewed Articles (in last 30 days)

