Jumat, 18 Maret 2011

Function Loop on Visual Basic

Loop statements on Visual Basic. These will run commands continually until the condition is false or while a condition is true.

Follow This Step :
1. Open Visual Basic 6.0 and start a new Standard EXE project.
2. On the General combo box of the code window, choose Form and the following text will appear:

Private Sub Form_Load()

End Sub


3. Here are some simple examples of using the Loop statement (use all of these examples in between the above two lines):

Dim i As Integer
Do Until i = 10
i = i + 1
Loop

Me.Caption = i


The above code creates an integer called 'i', which has a starting value of 0. The Loop statement, which starts with Do Until and ends with Loop adds 1 to 'i' and when 'i' reaches 10, it is displayed in the form's caption.

Dim i As Integer
Do While i < 100
i = i + 1
Loop

Me.Caption = i


The above code also creates an integer called 'i'. The statement does not exit while 'i' is less than the value of 100. that code keeps adding 1 to 'i' and when 'i' reaches 100, it is displayed in the form's caption.

Dim i As Integer
Do
i = i + 1
Loop While i < 100

Me.Caption = i


You can also include Until and While after Loop.

Related Post :



0 comments:

R