Terdapat 4 jenis perulangan pada program VB Net yang bisa anda gunakan.
Diantaranya :
1. For Next
2. While - End While
3. Do Until - Loop
4. Do While - Loop
Diantaranya :
1. For Next
2. While - End While
3. Do Until - Loop
4. Do While - Loop
Syntax :
1. For Next
For nvar = nawal to nakhir
perintah
perintah
Next nvar
atau bisa juga
For nvar = nawal to nakhir step nilai
perintah
perintah
Next nvar
2. While - End While
While kondisi
perintah
perintah
End While
3. Do Until - Loop
Do Until Kondisi
Perintah
Perintah
Loop
4. Do While - Loop
Do While kondisi
Perintah
Perintah
Loop
Design form perulangan pada program vb net
Pada TextBox1 propesties yang dirubah yaitu Multiline : True, ScrollBar : Vertical
Berikut merupakan contoh perulangan pada program VB Net
Public Class Form1
Dim j As Byte
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 1 To 10
ListBox1.Items.Add(i)
Next
For i = 10 To 1 Step -1
ListBox2.Items.Add(i)
Next
j = 1
While j <= 10
ComboBox1.Items.Add(j)
j += 1
End While
j = 10
Do Until j < 1
ListBox3.Items.Add(j & " BD")
j -= 2
Loop
j = 1
Do While j < 10
TextBox1.Text = TextBox1.Text & j & " BD" & vbCrLf
j += 2
Loop
End Sub
End Class
Penjelasan
j += 2 sama dengan perintah j = j + 2
Berikut merupakan contoh perulangan pada program VB Net
Public Class Form1
Dim j As Byte
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 1 To 10
ListBox1.Items.Add(i)
Next
For i = 10 To 1 Step -1
ListBox2.Items.Add(i)
Next
j = 1
While j <= 10
ComboBox1.Items.Add(j)
j += 1
End While
j = 10
Do Until j < 1
ListBox3.Items.Add(j & " BD")
j -= 2
Loop
j = 1
Do While j < 10
TextBox1.Text = TextBox1.Text & j & " BD" & vbCrLf
j += 2
Loop
End Sub
End Class
Penjelasan
j += 2 sama dengan perintah j = j + 2
Sumber : Mesran.net