Assalamualaikum Wr.Wb.
Oke ini adalah tugas teori saya
pada pertemuan ketiga, silahkan simak dan pelajari.
Struktur pengulangan atau Loop
digunakan untuk mengulang suatu blok perintah sampai kondisi tertentu.
— Proses pengulangan ini dapat
dikendalikan jumlahnya oleh aplikasi yang dibuat pada kondisi tertentu.
— Proses pengulangan akan
terus dikerjakan selama kondisi yang dibandingkan oleh proses tersebut masih
bernilai “Benar” (True).
— Jika kondisi yang
dibandingkan bernilai “Salah” (False), proses pengulangan akan berhenti dan
jalannya program akan dilanjutkan setelah proses pengulangan.
Struktur For–Next
— Struktur For – Next
digunakan untuk mengulang blok perintah dalam jumlah yang sudah ditentukan.
— Pada struktur ini tidak
perlu menentukan kondisi yang akan diuji tetapi perlu menentukan nilai awal dan
akhir variabel penghitung.
— Nilai variabel penghitung
secara otomatis akan bertambah atau berkurang setiap suatu pengulangan
dikerjakan
Nested For
— Pada proses semacam ini,
setiap satu proses pengulangan di struktur For–Next bagian luar akan
mengerjakan proses pengulangan di struktur For – Next bagian dalam sekian kali,
sesuai dengan seberapa banyak pengulangan tersebut dilakukan
While – End While
— Perulangan yang akan terus
menerus dilakukan selama kondisi memenuhi syarat (bernilaibenar) dan akan
berhenti jika kondisi bernilai salah
LATIHAN 1
- Code:
Public Class Pertemuan_4_Latihan_3_Teori
Private Sub btkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btkeluar.Click
Dim pesan As String
pesan = MsgBox("Are you sure want to exit", vbYesNo, "konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Pertemuan_4_Latihan_1_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit", vbYesNo,"konfirmasi")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_1_TeoriLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text =
End Sub
Private Sub btproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btproses.Click
Dim x As Integer
For x = 1 To 10
ListBox1.Items.Add(x)
Next x
End Sub
End Class
LATIHAN 2
- Code:
Public Class Pertemuan_4_Latihan_3_Teori
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btkeluar.Click
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", 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 btproses.Click
Dim x As Integer
For x = 10 To 1 Step -1
ListBox1.Items.Add(x)
Next
End Sub
Private Sub Pertemuan_4_Latihan_2_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "konfirmasi")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_2_Teori_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text =
End Sub
End Class
LATIHAN 3
- Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo,"konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub bthitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bthitung.Click
Dim x, y, i, hasil As Double
x = Val(TextBox1.Text)
y = Val(TextBox2.Text)
hasil = 1
For i = 1 To y
hasil = hasil * x
Next
TextBox3.Text = Str(hasil)
End Sub
Private Sub Pertemuan_4_Latihan_3_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo,"konfirmasi")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_3_Teori_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text =
End Sub
End Class
LATIHAN 4
- Code:
Public Class Pertemuan_4_Latihan_3_Teori
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", 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 7
ListBox1.Items.Add(WeekdayName(x))
Next
End Sub
Private Sub Pertemuan_4_Latihan_4_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "konfirmasi")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_4_Teori_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text =
End Sub
End Class
LATIHAN 5
- Code:
Public Class Pertemuan_4_Latihan_3_Teori
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 3
ListBox1.Items.Add(x & y)
Next
Next
End Sub
Private Sub Pertemuan_4_Latihan_5_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo,"konfirmasi")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_5_TeoriLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text =
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("Are You Sure Want to Exit ?", vbYesNo, "konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
End Class
LATIHAN 6
- Code:
Private Sub btkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btkeluar.Click
Dim pesan As String
pesan = MsgBox("Yakin Mau Keluar ?", vbYesNo,"konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Pertemuan_4_Latihan_6_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "konfirmasi")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Pertemuan_4_Latihan_6_TeoriLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text =
End Sub
Private Sub Btproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btproses.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
- Code:
Public Class Pertemuan_4_Latihan_3_Teori
Private Sub btcari_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btcari.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
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo,"konfirmasi"
If pesan = vbYes Then
End
End If
End Sub
Private Sub Pertemuan_4_Latihan_7_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "konfirmasi")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_7_TeoriLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text =
End Sub
End Class
KASUS 1
- Code:
Public Class Kasus 1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Are You Sure Want to Exit", vbYesNo, "kofirmasi")
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 12
ListBox1.Items.Add(MonthName(x))
Next
End Sub
Private Sub Kasus_1Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Sulthan"
End Sub
End Class
KASUS 2
- Code:
Public Class Kasus 2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pesan As String
pesan = MsgBox("Are You Sure Want to Exit ?", vbYesNo, "konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Kasus_2Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Sulthan"
For i = 1 To 30
ComboBox1.Items.Add(i)
Next
For i = 1 To 12
ComboBox2.Items.Add(i)
Next
For i = 2019 To 1990 Step -1
ComboBox3.Items.Add(i)
Next
End Sub
End Class
KASUS 3
- Code:
Public Class Kasus 3
'Sulthan'
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)
For i = x To y
If i Mod 2 = 0 Then
ListBox2.Items.Add(i)
ElseIf i Mod 2 = 1 Then
ListBox1.Items.Add(i)
End If
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("Are You Sure Want to Exit ?", vbYesNo, "konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Kasus_3Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Sulthan"
End Sub
End Class

Tidak ada komentar:
Posting Komentar