Struktur Pengulangan di VB.NET

  • Post
    codeorayo
    Keymaster
    none
    Lanjutan dari tutorial sebelumnya,tentang struktur pemrograman di VB.NET

    Ada 4macam struktur pengulangan :

    1.For-Next

    2.Do While – Loop

    3.Do Until – Loop

    4.While – End While

    untuk mencobanya mari kita buka VB.NET

    Pilih New Project->Windows Form Application->beri nama Struktur Pengulangan VB.NET->OK

    tambahkan 5 button dan 1 listbox.

    Masukan coding berikut :

    disertai penjelasan sederhana

    Code:

    Public Class Form1
    Dim i As Integer
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    ListBox1.Items.Clear()
    For Me.i = 1 To 10 ‘Pengulangan dilakukan dari 1 sampai 10
    ListBox1.Items.Add(i)
    Next
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    ListBox1.Items.Clear()
    i = 1
    Do While i <= 10 'kondisi i <= 10 true jadi program akan berkerja selama kondisi masih true ListBox1.Items.Add(i) i = i + 1 Loop End Sub Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click ListBox1.Items.Clear() i = 1 Do Until i > 10 ‘kondisi i > 10 adalah false karena i = 1 karena itu program akan berkerja hingga kondisi true
    ListBox1.Items.Add(i)
    i = i + 1
    Loop
    End Sub

    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
    ListBox1.Items.Clear()
    i = 1
    While i <= 10 'sama dengan do While ListBox1.Items.Add(i) i = i + 1 End While End Sub Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click ListBox1.Items.Clear() End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load End Sub End Class

    Selamat Mencoba ^_^

    Ampuh! Ini rahasia mengembangkan aplikasi secara instan, tinggal download dan kembangkan. Gabung sekarang juga! Premium Membership [PRIVATE] https://premium.codeorayo.com
  • You must be logged in to reply to this topic.