Senin, 10 April 2017

Contoh Penggunaan Looping pada Visual Studio 2015



KODINGNYA :

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label1.Text = "mulai angka"
        Label2.Text = "sampai angka"
        Button1.Text = "WHILE"
        Button2.Text = "Do while Loop"
        Button3.Text = " Do Loop Until"
        Button4.Text = "For...Next"
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim angka_awal, angka_akhir As Integer
        angka_awal = TextBox1.Text
        angka_akhir = TextBox2.Text
        ListBox1.Items.Clear()
        'belajar while
        While angka_awal < (angka_akhir + 1)
            ListBox1.Items.Add(angka_awal)
            angka_awal = angka_awal + 1
        End While
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim angka_awal, angka_akhir As Integer
        angka_awal = TextBox1.Text
        angka_akhir = TextBox2.Text
        ListBox1.Items.Clear()
        'belajar do while loop
        Do While angka_awal < (angka_akhir + 1)
            ListBox1.Items.Add(angka_awal)
            angka_awal += 1
        Loop
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim angka_awal, angka_akhir As Integer
        angka_awal = TextBox1.Text
        angka_akhir = TextBox2.Text
        ListBox1.Items.Clear()
        'belajar do loop until
        Do
            ListBox1.Items.Add(angka_awal)
            angka_awal += 1
        Loop Until angka_awal > (angka_akhir)
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim angka_awal, angka_akhir As Integer
        angka_awal = TextBox1.Text
        angka_akhir = TextBox2.Text
        ListBox1.Items.Clear()
        'belajar for next
        For angka_awal = angka_awal To angka_akhir
            ListBox1.Items.Add(angka_awal)
        Next
    End Sub
End Class


0 komentar:

Posting Komentar