Contoh Latihan 1-7 Menggunakan Perulangan (Struktur For – Next dan Nested For – Next, While – End While)
Latihan 1 Menggunakan For ... Next
Berikut Source Codenya :
Public Class latihan1
'nadiahtami 2017230007'
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Integer
For x = 1 To 10
ListBox1.Items.Add(x)
Next x
End Sub
End Class
Latihan 2 Menggunakan For ... Next
Berikut Source Codenya :
Public Class latihan2
'nadiahtami 2017230007'
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Integer
For x = 10 To 1 Step -1
ListBox1.Items.Add(x)
Next x
End Sub
End Class
Latihan 3 Menggunakan For ... Next
Berikut Source Codenya :
Public Class latihan3
'nadiahtami 2017230007'
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, y, i, hasil As Integer
x = Val(TextBox1.Text)
y = Val(TextBox2.Text)
hasil = 1
For i = 1 To y
hasil = hasil * x
On Error Resume Next
TextBox3.Text = Str(hasil)
Next
End Sub
End Class
Latihan 4 Menggunakan For ... Next
Berikut Source Codenya :
Public Class latihan4
'nadiahtami 2017230007'
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For i = 1 To 7
ListBox1.Items.Add(WeekdayName(i))
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
End Class
Latihan 5 Menggunakan Nested For ... Next
Berikut Source Codenya :
Public Class latihan5
'nadiahtami 2017230007'
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, y As Integer
For x = 1 To 3
For y = 1 To 2
ListBox1.Items.Add(x & y)
Next y
Next x
End Sub
End Class
Latihan 6 Menggunakan While – End While
Berikut Source Codenya :
Public Class latihan6
'nadiahtami 2017230007'
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Integer
x = 1
While x <= 10
ListBox1.Items.Add(x)
x = x + 1
End While
End Sub
End Class
Latihan 7 Menggunakan While – End While
Berikut Source Codenya :
Public Class latihan7
'nadiahtami 2017230007'
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, i As Integer
x = Val(TextBox1.Text)
i = 1
x = x + 1
ListBox1.Items.Clear()
While i < 11
If x Mod 2 = 0 Then
ListBox1.Items.Add(x)
i = i + 1
End If
x = x + 1
End While
End Sub
End Class
Komentar
Posting Komentar