Wednesday, February 16, 2011

Loops

This is a example of a FOR LOOP. The For is the keyword you use to start the loop.

  For i = 1 To 10 Step 1  
       Print("programmershelp")  
     Next i  
   End Sub  

basically what is happening is that it is going to step threw by 1 until it gets to 10

This is a example of Do (While last)

 Public Class Form1  
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
     Dim x As Integer  
     Do  
       Debug.Print("hello")  
       x = x + 1  
     Loop Until x = 10  
   End Sub  
 End Class  

Loop check when the loops ends. So this code means that the loop is going to continue to run until x = 10 then it will stop.

This is a example of Do (While first)

 Public Class Form1  
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
     Dim x As Integer  
     Do Until x = 10  
       Debug.Print("hello")  
       x = x + 1  
     Loop  
   End Sub  
 End Class  

Do checks when the loop starts.

This is a example of a For Each

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
     Dim siteName As String  
     Dim singleChar As Char  
     siteName = "HTTP://NET-INFORMATIONS.COM"  
     For Each singleChar In siteName  
       MsgBox(singleChar)  
     Next  
   End Sub  

This is going to display each letter one by one until it spells the whole thing out.

No comments:

Post a Comment