1. For ... Next Loop
Bentuknya :
For counter = startNumber to endNumber (Step increment)
One or more VB statements
Next
Berikut ini contoh penggunaan For Next Loop:
1. For Next
- Dim counter As Integer
- For counter = 1 To 10
- ListBox1.Items.Add(counter)
- Next
2. For Next Step
- Dim counter As Integer
- For counter = 0 To 10 Step 2
- ListBox1.Items.Add(counter)
- Next
3. For Next Step
- Dim counter As Integer
- For counter = 100 To 5 Step -5
- ListBox1.Items.Add(counter)
- Next
4. For Next Conditional
- Dim counter As Integer
- For counter = 1 To 10
- If counter > 6 Then
- Exit For
- Else
- ListBox1.Items.Add(counter)
- End If
- Next
2. Do Loop
Bentuknya :
a) Do While condition
Blok satu atau lebih statements
Loop
b) Do
Blok satu atau lebih statements
Loop While condition
c) Do Until condition
Blok satu atau lebih statements
Loop
d) Do
Blok satu atau lebih statements
Loop Until condition
Berikut ini contoh penggunaan Do Loop:
Bentuknya :
a) Do While condition
Blok satu atau lebih statements
Loop
b) Do
Blok satu atau lebih statements
Loop While condition
c) Do Until condition
Blok satu atau lebih statements
Loop
d) Do
Blok satu atau lebih statements
Loop Until condition
Berikut ini contoh penggunaan Do Loop:
1. Do While
- Dim counter As Integer
- counter = 1
- Do While counter <= 100
- ListBox1.Items.Add(counter)
- counter += 1
- Loop
2. Do Loop
- Dim counter, sum As Integer
- Do
- counter += 1
- sum += counter
- ListBox1.Items.Add(counter & vbTab & sum)
- If counter = 100 Then
- Exit Do
- End If
- Loop
3. Do Until
- Dim counter As Integer
- counter = 1
- Do Until counter = 10
- ListBox1.Items.Add(counter)
- counter += 1
- Loop
Tidak ada komentar:
Posting Komentar