You are on page 1of 22

Case of, Looping

MATERI KE-3
Isi Daftar Hadir Dulu Ya Di Sia Maupun Di Daring!!!!
Case of
Select Case [variable]
Case [condition 1]
[Statement 1]
Case [condition 2]
[Statement 2]
Case [condition n]
[Statement n]
Case Else
[Statement else]
End Select
Contoh
A=cells(1,2)
Select Case A
Case 1
cells(2,2)= “SD"
Case 2
cells(2,2)= “SMP"
Case 3
cells(2,2)= “SMA“
Case Else
◦ Cells(2,2)=“Tidak Sekolah”
End Select
Contoh
A=cells(1,2)
Select Case A
Case 1
cells(2,2)= “SD"
Case 2
cells(2,2)= “SMP"
Case 3
cells(2,2)= “SMA"
End Select
Contoh
A=cells(1,2)
Select Case A
Case 1
cells(2,2)= “SD“
cells(3,2)= “Sekolah Dasar adalah tingkat” & a
Case 2
cells(2,2)= “SMP"
cells(3,2)= “Sekolah Menengah Pertama adalah tingkat” & a
Case 3
cells(2,2)= “SMA“
cells(3,2)= “Sekolah Menengah Atas adalah tingkat” & a
End Select
Is <> 40 (tidak sama dengan)
A=cells(1,2)
Select Case A
Case Is <= 10
cells(2,2) = “Kurang"
Case Is <= 20
cells(2,2) = “Lumayan"
Case Is <30 A
cells(2,2) = “Bagus"
Case Else
cells(2,2) = “Mantap"
End Select
contoh
a = Cells(1, 2)
Select Case a
Case 1
Cells(2, 2) = "Kurang"
Case 2 To 3
Cells(2, 2) = "Lumayan"
Case 4, 6 To 8 jika pakai if  if (a=4) or (a>=6 and a<=8)
Cells(2, 2) = "Bagus"
Case Else
Cells(2, 2) = "Mantap"
End Select
Looping (Pengulangan)
For-Next
Pengulangan dengan bilangan bulat
Sintak
For var = nilai_awal to nilai_akhir [Step nilai]
Statemen 1

Statemen k
Next Var
Contoh
For i = 5 To 9
Cells(i, 2) = i * 2
Next I
Contoh
A=cells(1,1) 3
For i = 1 To 9 i=4
c=c+a c=3
Cells(i, 2) = c * 2
Next I
6
12
18
Contoh
c=2
For i = 1 To 9 i=2
c=c+I c=5
Cells(i, 2) = c & " x 2 = " & c * 2
Next I
3x2=6
5 x 2 = 10
8 x 2 = 16
Hasil
Bagaimana Sintak
c=3
For i = 1 To 9
c=c+I
Cells(i, 2) = …………
Next I
“No. “&I&” | “&3&” x “ &I&” adalah “& i*3
Contoh
C=cells(1,2)
For i = 1 To 9
Cells(i, 3) = "No ." & i & "| " & c & " x " & i & " adalah " & c * i
Next i
Bagaimana Sintak
A=cells(1,1) 3
For t = 9 To 1 Step -3
j=j+1 j=1
A=a+3 a=12
Cells(j, 3) = a + t 17
Next t
For dan IF
a = Cells(1, 1)
For i = 1 To 9
If i Mod 2 = 0 Then
Cells(i, 2) = i * a
Else
Cells(i, 2) = i * 5
End If
Next i
Pengulangan dengan Kondis
Pengulangan selama kondisi bernilai benar

Do While <Kondisi>
<Statement Block>
[ jika ingin keluar bisa gunakan Exit Do]
Loop
Contoh
a = Cells(1, 1)
Do While a < 10
j=j+1
Cells(j, 4) = a + j
a=a+2
Loop
Do Until <Kondisi>
<Statement Block>
[Exit Do]
Loop
Do
<Statement Block>
[Exit Do]
Loop Until<Kondisi>
Do
<Statement Block>
[Exit Do]
Loop While <Kondisi>

You might also like