VB.Net Tutorial/Statements/Counter Controlled Repetition

Материал из VB Эксперт
Перейти к: навигация, поиск

Using the For/Next structure to demonstrate counter-controlled repetition.

<source lang="vbnet">Module Tester

   Sub Main()
       Dim counter As Integer
     For counter = 2 To 10 Step 2
        Console.Write(counter & " ")
     Next
   End Sub 

End Module</source>

2 4 6 8 10

Using the While structure to demonstrate counter-controlled repetition.

<source lang="vbnet">Module Tester

   Sub Main()
       Dim counter As Integer = 2
     While counter <= 10 
        Console.Write(counter & " ")
        counter += 2 
     End While
   End Sub 

End Module</source>

2 4 6 8 10