Latihan 8-12 menggunakan Perulangan (Do While – Loop, Do – Loop While, Do Until – Loop, Do – Loop Until)
Latihan 8 - Perulangan Do While – Loop
Berikut Source Codenya :
Public Class latihan8
'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 i As Integer = 0
Do While i <= 10
ListBox1.Items.Add("Perulangan dengan Do While ke" & i)
i = i + 1
Loop
End Sub
End Class
Berikut Source Codenya :
Public Class latihan9
'nadiahtami 2017230007'
Dim halaman As Byte
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pesan As String
pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub latihan9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
halaman = 1
Do While halaman <= 10
ComboBox1.Items.Add(halaman)
halaman = halaman + 1
Loop
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
halaman = 1
Do While halaman <= 10
ComboBox2.Items.Add(halaman)
halaman = halaman + 1
Loop
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim hasil As Double = 1
For i = 1 To Val(ComboBox2.Text)
hasil = hasil * ComboBox1.Text
Next
TextBox1.Text = hasil
End Sub
End Class
Latihan 10 - Perulangan Do – Loop While
Berikut Source Codenya :
Public Class latihan10
'nadiahtami 2017230007'
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim pesan As String
pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x
x = TextBox1.Text
Do
x = x Mod 2
If x = 0 Then
MsgBox("Bilangan Genap")
Exit Do
ElseIf x = 1 Then
MsgBox("Bilangan Ganjil")
Exit Do
End If
Loop While Not x
End Sub
End Class
Latihan 11 - Perulangan Do Until – Loop
Berikut Source Codenya :
Public Class latihan11
'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 i As Integer
i = 1
ListBox1.Items.Clear()
Do Until i > 10
ListBox1.Items.Add(i)
i += 1
Loop
End Sub
End Class
Latihan 12 - Perulangan Do – Loop Until
Berikut Source Codenya :
Public Class latihan12
'nadiahtami 2017230007'
Sub ulang(ByVal angka As Byte)
If angka > 0 Then
ListBox1.Items.Add("*" & angka & "*")
End If
End Sub
Sub ulang_cetak(ByVal angka As Byte)
If angka > 0 Then
ListBox1.Items.Add("*" & angka & "*")
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.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 Byte = 0
Do
Call ulang(x)
x = x + 2
Loop Until x > (TextBox1.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim x As Byte = 0
Do
Call ulang_cetak(x)
x = x + 3
Loop Until x > (TextBox1.Text)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = ""
ListBox1.Items.Clear()
End Sub
End Class
Komentar
Posting Komentar