Vb. NET Learning Notes (Circular statement)

Source: Internet
Author: User
Tags exit
Notes | loops | statement LOOP statement


Vb. NET, the loop statements are divided into: Do While loop, for Next, for each three.



Do While loop
There are three forms of do-while loops, which are used for the prior-timed use of loops that do not know beforehand. Be careful when using do-while loop statements, because they are indeterminate loops, so be cautious about not causing a dead loop.



Doing while Loop example

Public Class Testa

Public Sub New ()

Dim I as Int32



i = 1

Do While I < 100 ' first judge after execution

i + 1

Exit do

Loop



i = 1

Todo

i + 1

Exit do

Loop while I < 100 ' first execute after judgment



While I < m ' Do while I < 100

i + 1

Exit while

End While



End Sub

End Class








For Next
is not the same as do-while loops, for next is the bounds loop. The For statement specifies the loop control variable, lower bound, upper bound, and optional step value.



For next example

Public Class Testa

Public Sub New ()

Dim I as Int32



For i = 0 to 2



Next I



End Sub

End Class






For each
For each is also a non quantitative loop, for each is the traversal of each element in the collection. If you need to iterate over a collection of objects, you should use for each.



For each example

Public Class Testa

Public Sub New ()

Dim Found as Boolean = False

Dim mycollection as New Collection

For each MyObject as Object in mycollection

If myobject.text = "Hello" Then

Found = True

Exit for

End If

Next



End Sub

End Class






Simple statement Introduction, we are here, the other statements in the future of the gradual deepening of vb.net, we will explain

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.