Visual Basic Lanjutan Praktikum 3 - Perulangan (Do While - Loop)



Assalamu’alaikum warahmatullahi wabarakatuh..
Kembali lagi bersama saya Ilham Ramadhan, saya akan melanjutkan pelajaran yang pernah saya bahas silahkan cek di beranda yaa. Kali ini saya akan membahas tentang Visual Basic Lanjutan (Perulangan), oke langsung saja kita bahas tanpa berlama-lama, oke check it out...

Sebelumnya Kalau kalian mau lihat pembahasan kita minggu lalu ada di bawah sini :
  1. Visual Basic Lanjutan Teori 1 Variabel dan Type Data
  2. Visual Basic Lanjutan Praktikum 1 Operator
  3. Visual Basic Lanjutan Teori 2 Percabangan (Struktur If-Then, If-Then-Else dan Nested IF)
  4. Visual Basic Lanjutan Praktikum 2 Percabangan (IIF dan Select Case)
  5. Visual Basic Lanjutan Teori 3 - Perulangan

Perulangan (Do While - Loop)
  • Perulangan yang akan terus menerus dilakukan selama kondisi memenuhi syarat (bernilai benar) dan akan berhenti jika kondisi bernilai salah.


Keterangan :
  • Ketika program dijalankan maka hal yang pertama kali dikerjakan adalah menguji kondisi.
  • Ketika program dijalankan maka hal yang pertama kali dikerjakan adalah menguji kondisi.
Oke langsung saja kita ke contoh soal latihan yaa😁

Latihan 8

  • Source Code
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "laptopinformatika.com"
    End Sub

    Private Sub btproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btproses.Click
        Dim i As Integer = 0
        Do While i <= 10
            ListBox1.Items.Add("Perulangan dengan do while" & i)
            i = i + 1
        Loop
    End Sub

    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, "laptopinformatika.com")
        If pesan = vbYes Then
            End
        End If
    End Sub
End Class

Latihan 9



  • Source Code
Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Text = "laptopinformatika.com"
        Dim halaman As Byte
        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

        Dim halaman As Byte
        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

    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, "laptopinformatika.com")
        If pesan = vbYes Then
            End
        End If
    End Sub

End Class



Perulangan (Do - Loop While)

  • Struktur Do – Loop While merupakan struktur pengulangan yang metodenya sama dengan struktur Do While – Loop.
Keterangan :
  • Ketika program dijalankan maka hal yang pertama kali dikerjakan adalah menjalankan blok program ekspresi.
  • Kemudian akan memeriksa kondisi pada Loop While, jika kondisi bernilai benar maka ekspresi akan dijalankan kembali (berulang).
  • Jika kondisinya salah maka prosesnya akan berhenti dan program akan dilanjutkan dengan menjalankan perintah dibawah Loop While.

Latihan 10



  • Source Code


Public Class Form3

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "laptopinformatika.com"
    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("Genap")
                Exit Do
            ElseIf x = 1 Then
                MsgBox("Ganjil") 'laptopinformatika.com
                Exit Do
            End If
        Loop While Not x
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        TextBox1.Text = ""
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim pesan As String
        pesan = MsgBox("Are you sure want to exit", vbYesNo, "laptopinformatika.com")
        If pesan = vbYes Then
            End
        End If
    End Sub
End Class

Latihan 11



  • Source Code


Public Class Form4

    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "laptopinformatika.com"
    End Sub

    Private Sub btproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btproses.Click
        Dim i As Integer
        i = 1
        ListBox1.Items.Clear()
        Do Until i > 10
            ListBox1.Items.Add(i) 'laptopinformatika.com
            i += 1
        Loop
    End Sub

    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, "laptopinformatika.com")
        If pesan = vbYes Then
            End
        End If
    End Sub
End Class

Latihan 12



  • Source Code


Public Class Form5

    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "laptopinformatika.com"
    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

    Sub ulang(ByVal angka As Byte)
        If angka > 0 Then
            ListBox1.Items.Add("" & angka & "") 'laptopinformatika.com
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim X As Byte = 0
        Do
            Call ulang_cetak(X)
            X = X + 3
        Loop Until X > (TextBox1.Text)
    End Sub

    Sub ulang_cetak(ByVal angka As Byte)
        If angka > 0 Then
            ListBox1.Items.Add("" & angka & "") 'laptopinformatika.com
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ListBox1.Items.Clear()
        TextBox1.Text = ""
    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("Are you sure want to exit", vbYesNo, "laptopinformatika.com")
        If pesan = vbYes Then
            End
        End If
    End Sub
End Class

Oke segitu dulu ya teman-teman untuk materi dan pelajarannya, nanti mudah-mudahan aja bisa lanjut belajar lagi lain waktu hehehe. Comment dan share ya teman-teman untuk membuat materi selanjutnya dan berikan saran dan masukannya... Thank you...! 😉😉😉

Berlangganan update artikel terbaru via email:

4 Responses to "Visual Basic Lanjutan Praktikum 3 - Perulangan (Do While - Loop)"

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel