Facebook

gravatar

Contoh Pemograman

Pengulangan

Pengulangan adalah suatu instruksi dalam pemrograman agar sekelompok perintah dilaksanakan dengan berulang sampai dengan suatu kondisi terpenuhi.

Berikut contoh pengulangan dalan visual studio 2008


1. For
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim I As Integer
        ListBox1.Items.Clear()
        For I = 1 To 10
            ListBox1.Items.Add(I)
        Next
End Sub

2. Do While
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim I As Integer
        ListBox1.Items.Clear()
        Do While I <= 10
            ListBox1.Items.Add(I)
            I = I + 1
        Loop
    End Sub

3. For Next
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim I As Integer
        ListBox1.Items.Clear()
        For I = Val(TextBox2.Text) To Val(TextBox3.Text)
            ListBox1.Items.Add(I)
        Next
    End Sub

4. Do While Next
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim I As Integer
        ListBox1.Items.Clear()
        I = Val(TextBox2.Text)
        Do While I <= Val(TextBox3.Text)
            ListBox1.Items.Add(I)
            I = I + 1
        Loop
    End Sub

5. For Ganjil & Genap
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim I As Integer
        ListBox1.Items.Clear()
        For I = Val(TextBox2.Text) To Val(TextBox3.Text)
            If I Mod 2 = 0 Then
                ListBox1.Items.Add("Bil Genap " & I)
            Else
                ListBox1.Items.Add("Bil Ganjil " & I)
            End If
        Next
    End Sub

7. For 3,-6,9,-12, 15
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Dim I As Integer
        ListBox1.Items.Clear()
        For I = Val(TextBox2.Text) To Val(TextBox3.Text)
            If I Mod 3 = 0 And I Mod 2 = 0 Then
                ListBox1.Items.Add(I * -1)
            Else
                If I Mod 3 = 0 Then
                    ListBox1.Items.Add(I)
                End If
            End If
        Next
    End Sub

8. Do While 3,-6,9,-12, 15
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Dim I As Integer
        ListBox1.Items.Clear()
        I = Val(TextBox2.Text)
        Do While I <= Val(TextBox3.Text)
            If I Mod 3 = 0 And I Mod 2 = 0 Then
                ListBox1.Items.Add(I * -1)
            Else
                If I Mod 3 = 0 Then
                    ListBox1.Items.Add(I)
                End If
            End If
            I = I + 1
        Loop
    End Sub



Welcome

Blog ini bertujuan untuk menyimpan catatan. Selain itu juga blog ini sebagai pembelajaran untuk saya sendiri & orang lain. Silahkan kunjungi blog ini kapanpun anda mau.



By : ----- Ali Kusumadinata -----

Yahoo

Chating

Koleksi

Category