Struktur Kontrol Selection / Pemilihan
Ada beberapa variasi dari struktur kontrol selection yaitu:
- Simple Selection (simple IF Statement)
- Simple Selection tanpa cabang
- Combined Selection
- Nested Selection
- Linear Nested IF Statement
- Non-Linear IF Statement
1. Simple Selection
Simple selection terjadi jika harus memilih diantara dua alternatif yang ada, tergantung dari hasil kondisi apakah True atau false.
Keyword yang digunakan adalah : IF, THEN, ELSE, dan END IF
Contoh
IF saldo < $300 THEN
bunga = 0.05
ELSE
bunga = 0.1
ENDIF
2. Simple Selection Tanpa Cabang
Simple selection ini terjadi jika sebuah statement hanya bisa dikerjakan bila kondisinya adalah TRUE
Contoh:
IF Saldo > $300 THEN
bunga = saldo * 0.1
ENDIF
3. Combined Selection
Combined Selection terjadi jika kondisi yang harus diperiksa lebih dari satu. Kondisi tersebut dapat dihubungkan dengan menggunakan AND atau OR.
Contoh:
IF saldo > 300 AND kode = 1 THEN
bunga = saldo * 0.1
ELSE
bunga = saldo * 0.05
ENDIF
Statement bunga = saldo *0.1, akan bisa dikerjakan jika kedua kondisi yaitu saldo > 300 dan Kode = 1 bernilai TRUE. Hal ini dikarenakan penghubung yang digunakan adalah AND
3. Nested Selection
Tabel kebenaran
Nested selection terjadi, jika di dalam IF terdapat statement IF yang lain.
Ada dua jenis nested selection
Linear Nested IF statement
Non-Linear Nested IF statement
Linear Nested IF Statement
Linear Nested terjadi jika satu kondisi di cek untuk beberapa nilai.
Contoh:
IF record_code=‘A’ THEN
increment counter_A
ELSE
IF record_code=‘B’ THEN
increment counter_B
ELSE
IF record_code=‘C’ THEN
increment counter _C
ELSE
increment error_counter
ENDIF
ENDIF
ENDIF
Non-Linear Nested IF
Non-Linear Nested IF Statement terjadi jika beberapa kondisi harus diperiksa sebelum suatu statement dikerjakan.
Contoh
IF student_attendance=part_time THEN
IF student_gender=female THEN
IF student_age >21 THEN
add 1 to mature_fem_pt_students
ELSE
add 1 to young_fem_pt_students
ENDIF
ELSE
add 1 to male_pt_students
ENDIF
ELSE
add 1 to full_time_students
ENDIF
Tugas : buat contoh lain selain contoh di atas untuk :
- Simple Selection (simple IF Statement)
- Simple Selection tanpa cabang
- Combined Selection
- Nested Selection
- Linear Nested IF Statement
- Non-Linear IF Statement
1. simple selection :
BalasHapusif saldo < $500 then
bunga= 0,010
else
bunga = 0,001
end if
2. simple slection tanpa cabang
if saldo >$500 then
bunga=saldo*0,001
end if
3. combined selection
if saldo >$500 and code =3 then
bunga=saldo*0,001
else
bunga=saldo*0,010
end if
4. nested selection (Linear Nested if statement)
if record_code='B' then
increment counter_B
else
if record_code='C' then
increment counter_C
else
if record_code='D' then
ncorement counter_D
else
increment error_counter
end if
end if
end if
(Non Linear IF statement)
if doctor_attendence=part_time then
if doctor_gender=male then
if doctor_age>40 then
add 1 to specialist_male_pt_doctors
else
add 1 to old_male_pt_doctors
end if
else
add 1 to female_pt_doctors
add 1 to full_time_doctors
end if
maaf pak saya gak paham sama materinya.
pake maaf mlolo ????? huuuuuuffffftt x_x
BalasHapusMaaf pa saya kurang faham
BalasHapus*Simple Selection
BalasHapusIF saldo < $800 THEN
bunga = 0.8
ELSE
bunga = 0.3
END IF
*Simple Selection Tanpa Cabang
IF Saldo > $800 THEN
bunga = saldo * 0.3
ENDIF
*Combined Selection
IF saldo > 800 AND kode = 3 THEN
bunga = saldo * 0.3
ELSE
bunga = saldo * 0.08
ENDIF
*nested Selection
IF record_code=‘P’ THEN
increment counter_P
ELSE
IF record_code=‘Q’ THEN
increment counter_Q
ELSE
IF record_code=‘R’ THEN
increment counter _Q
ELSE
increment error_counter
ENDIF
ENDIF
ENDIF
*Non Linear IF statement
if teacher_attendence=part_time then
if teacher_gender=female then
if teacher_age>30 then
add 1 to math_female_pt_teacher
else
add 1 to old_female_pt_teacher
end if
else
add 1 to male_pt_teacher
add 1 to full_time_teacher
end if
ga tauu dah pa bneer aph gaa pusiing sayaa
kelaz-904
BalasHapusnim-093330702
ANNISA NURUL JANAH/ 904/ 093330688/ KA:
BalasHapus+Simple Selection
IF saldo < $600 THEN
bunga = 0.6
ELSE
bunga = 0.2
END IF
+Simple Selection Tanpa Cabang
IF Saldo > $600 THEN
bunga = saldo 0.2
ENDIF
+Combined Selection
IF saldo > 600 AND kode = 2 THEN
bunga = saldo * 0.2
ELSE
bunga = saldo * 0.06
ENDIF
+nested Selection
IF record_code=‘D’ THEN
increment counter_D
ELSE
IF record_code=‘E’ THEN
increment counter_E
ELSE
IF record_code=‘F’ THEN
increment counter _E
ELSE
increment error_counter
ENDIF
ENDIF
ENDIF
+ Non Linear IF statement
if Profesor_attendence=part_time then
if Profesor_gender=female then
if Profesor_age>45 then
add 1 to math_female_pt_Profesor
else
add 1 to old_female_pt_Profesor
end if
else
add 1 to male_pt_Profesor
add 1 to full_time_Profesor
end if
1.simple selection
BalasHapusif nilai >= 60 then
write (“Lulus”)
else
write (“Tidak Lulus”)
end if
2.selection tanpa cabang
If (Nilai_Akhir) >= 55 Then
write ("lulus")
End If
3.combinasi seleksi
if nilai >=85 And nilai <=100 then
grade "A"
else
if nilai >=75 AND nilai <85 then
grade "B"
else
grade "C"
End If
4. nested selection
If (bil>0) then
writeln(‘Bilangan positif’);
If (bil mod 2=0) then
writeln (‘Bilangan genap’)
Else
writeln (‘Bilangan ganjil’);
End
Else
writeln (‘Bilangan negatif’);
End if
End if
5. Linear Nested IF Statement
if A >= B then
writeln( A,’ adalah terbesar’)
else
if A >= C then
writeln( C,’ adalah terbesar’)
else
if B >= C then
writeln( B,’ adalah terbesar’)
else
writeln( C,’ adalah terbesar’)
end if
end if
end if
6.non-linier nested
If Jenis = “Pria” Then
If Status = “Sudah” then
Print “Ayah”
Else
Print “Jejaka”
End If
Else
If Status = “Sudah” Then
Print “Ibu”
Else
Print “Perawan”
End If
End If
1.simple selection
BalasHapusif saldo<$200 then
bunga = 0.02
else
bunga = 0.1
end if
2.Simple selection tanpa cabang
if saldo >&200 then
bunga = saldo *0.1
end if
3. combined selection
if saldo >200 and code = 2 then
bunga = 0.1
else
bunga = saldo *0.02
end if
statment bunga = saldo *0.1 akan bisa dikerjakan jika kedua kondisi yaitu saldo>200 dan kode = 2 bernilai TRUE.hal ini dikarenakan penghubungan yang digunakan adalah AND
4.Nested selection
if.record_code = 'C' then
increment counter _ C
else
if.record_code = 'D' then
increment counter _ D
else
if.record_code = 'E'
increment counter _ E
else
increment error _ counter
end if
end if
end if
5.non linier nested
if police _attendence = part_time then
if police_gender = female then
if police_age >50 then
add 1 to math_female_PT_police
else
add 1 to old_female_pt_police
end if
add 1 to male_pt_police
add 1 to full_time police
end if
tiapa komen pasti ada kata maaf.. bosen lihat nya
BalasHapusKomentar ini telah dihapus oleh pengarang.
BalasHapusRIKI YAKUB_904_093330718
BalasHapus1,Simple Selection
if IPK > 3,10 Then
write " dapat beasiswa"
else
write "tidak dapat beasiswa"
end if
2, simple selection tanpa cabang
if IPK > = 3.00 then
write "dapat beasiswa"
3, combined selection
if IPK > = 3,50 and IPK < =4,00 then
nilai = A
else
if IPK > = 3,00 and IPK < = 3,50 then
nilai = B
else
if IPK > = 2,50 and IPK < = 3,00 then
nilai = C
else
if IPK > = 2,00 and IPK < = 2,50 then
nilai = D
else
nilai = E
end if
4,Nasted Selection
if tran-code = "A" then
add anew customer record
else
if tran-code = "C" then
change customer record
else
if tran-code = "D" then
Delete customer record
else
display error message
end if
end if
end if
5, Non Linear nasted
if employee-code = "H" then
if hours-worked < = 40 then
calculate pay at hourly rate
else
calculate pay with overtime
end if
else
pay base salary
end if
susaaaaaaaaaaaaahhhhhhhhhhhhhh baggteeeeettttttt
@riki brasa asal2an x ....wkwkwkwkkkkkkkk....maaf pak saya koment.... gubraaaakk
BalasHapusmateri ini agak rumit pak, saya kurang paham tentang materi ini...
BalasHapustes
BalasHapusKomentar ini telah dihapus oleh pengarang.
BalasHapussaya kurang paham pak..!!
BalasHapussaya kurang paham dengan materi ini pak ,,
BalasHapuspak mending jelasin di kelas aja
BalasHapusbanyak anak2 yg belum faham
sepakat....!!!!
BalasHapussaya juga kurang faham pak!!!!!!!
dahsyat sekali..
BalasHapusga faham pak.......^_^
IIS SELVIA D.K./093330746
BalasHapus1. Simple Selection
IF nilai > 90 THEN
predikat = A
ELSE
predikat = B
ENDIF
2. Simple Selection Tanpa Cabang
IF nilai > 90 THEN
predikat = nilai * A
ENDIF
3. Combined Selection
IF nilai > 90 AND kerajinan = A THEN
predikat = nilai * A
ELSE
predikat = nilai * B
ENDIF
4. Nested Selection
IF record_code=‘1’ THEN
increment counter_1
ELSE
IF record_code=‘2’ THEN
increment counter_2
ELSE
IF record_code=‘3’ THEN
increment counter _3
ELSE
increment error_counter
ENDIF
ENDIF
ENDIF
5. Non-Linear Nested IF
IF student_attendance=part_time THEN
IF student_gender=male THEN
IF student_age > 19 THEN
add 1 to mature_male_pt_students
ELSE
add 1 to young_male_pt_students
ENDIF
ELSE
add 1 to female_pt_students
ENDIF
ELSE
add 1 to full_time_students
ENDIF
Maaf pak,selvi kurang paham ma materinya,jadi cuma bisa jawab sebisanya pak.maaf kalau salah!!
Pak,, absen + jawaban'a..
BalasHapus1. simple selection :
IF acc_balanced < 300 THEN
service_change = 5
ELSE
service _change = 2
ENDIF
2. simple selection tanpa cabang :
IF no_mahasiswa invalid THEN
hapus record mahasiswa
END IF
3. combined selection
IF student_attendance = parttime
AND studentgender = female THEN
add 1 to fem_part_student_count
ENDIF
4. nested selection
IF record_code = '1' THEN
increment_counter_1
ELSE IF record_code = '2' THEN
increment_counter_2
ELSE IF record_code = '3'
THEN
increment_counter_3
ELSE BEGIN
increment_error_count
ENDIF
ENDIF
ENDIF
5. non-linear IF statement
IF student_attendance_part_time THEN
IF student_gender = female THEN
IF student_age >21 THEN
add 1 mature _female_student
ELSE
add 1 young_female_student
ENDIF
ELSE
add 1 to male_student
ENDIF
ELSE
add 1 to full_time_student
ENDIF
1.simple selection :
BalasHapusif jam kerja > 12 then
write "lembur"
else
write "tidak lembur"
end if
2.simple selection tanpa cabang :
if jam kerja < 12 then
write "tidak lembur"
end if
3.combined selection :
if jam kerja > 8 and jam kerja < 5 then
lembur = Rp. 20000
else
if jam kerja > 5 and jam kerja < 2 then
lembur = Rp. 10000
end if
4.nested selection :
if jam kerja_masuk = 8 then
dibayar Rp.75000
else
if jam kerja_masuk = 5 then
dibayar Rp.55000
else
if jam kerja_masuk = 3 then
dibayar Rp.45000
else
if jam kerja > 3 tidak dibayar
end if
end if
5.non-linear nasted :
if jumlah barang > 300 and < 500 then
potongan 15%
else
if jumlah barang > 200 then
potongan 10%
else
if jumlah barang > 99 then
potongan 5 %
else
potongan 0%
end if
end if
1. Simple Selection
BalasHapusIF rajin belajar Then
write akan naik kelas
Else
write tidak akan naik kelas
EndIf
2. Simple Selection Without Branch
IF " rajin belajar " Then
write " akan naik kelas "
EndIf
3. Combined Selection
If rajin belajar AND mengerjakan tugas Then
akan naik kelas
else
jadi juara kelas
EndIf
4. Nested Selection
If (n>90) and (n<=100) then
nilai_A
else
If (n>70) and (n<=90) then
nilai_B
else
If (n>40) and (n<=70) then
nilai_C
else
nilai_D
EndIf
EndIf
EndIf
5. Non-Linear Nested
If (n>90) and (n<=100)Then
If (n>70) and (n<=90) then
If (n>40) and (n<=70) then
nilai_A
else
nilai_B
EndIf
else
nilai_C
EndIf
else
nilai_D
EndIf
nama : vega halwa nuri
kelas : 904
nim : 093330767
1. Simple Selection :
BalasHapusIf Penjualan < Rp.1000 Then
bonus = Rp.100
Else
bonus = Rp. 50
EndIf
2. Simple Selection Tanpa Cabang :
If Penjualan > Rp. 1000 Then
bonus = penjualan Rp. 50
EndIf
3. Combined Selection :
If Penjualan > 1000And kode =2 Then
bonus = penjualan 50
Else
bonus = penjualan 100
EndIf
4. Nested Selection :
maaf pak ,saya ga tau lagi.
1.simple selection
BalasHapusIF SELL<$5000THEN
DISCOUNT = 0.025
ELSE
DISCOUNT = 0.5
END IF
2.SIMPLE SELECTION TANPA CABANG
IF SELL>$5000THEN
DISCOUNT=SELL*0.5
END IF
3.COMBINED SELECTION
IF SELL>$5000 AND CODE = 1 THEN
DISCOUNT = SELL*0.5
ELSE
DISCOUNT=SELL*0.025
END IF
4 NESTED SELECTION
IF RECORD_CODE='A'THEN
INCREMENT CHASIER_A
ELSE
IF RECORD_CODE='B'THEN
INCREMENT CHASIER_B
ELSE
IF RECORD_CODE='C'
INCREMENT CHASIER_C
ELSE
INCREMENT ERROR_CHASIER
END IF
END IF
END IF
5.NON LINEAR
IF CHASIER_ATTENDANCE=PART_TIME THEN
IF CHASIER_LONG WORKING>1 THEN
ELSE
ADD 1 TO ALLOWANCE_CHASIER
ELSES
ADD 1 TO OVERTIME_CHASIER
END IF
ELSE
PAY HIGHER SALARIES
END IF
RANI_904 NIM 093330758
1)Simple Selection
BalasHapusContoh
IF harga < Rp1.000.000 THEN
discount = 0.05
ELSE
discount = 0.1
ENDIF
2)Simple Selection Tanpa Cabang
Contoh:
IF harga > $300 THEN
discount = saldo * 0.1
ENDIF
3)Combined Selection
IF harga > Rp 1.000.000 AND kode = 1 THEN
discount = harga * 0.1
ELSE
discount = harga * 0.05
ENDIF
Statement discount = harga *0.1, akan bisa dikerjakan jika kedua kondisi yaitu saldo > Rp 1.000.000 dan Kode = 1 bernilai TRUE. Hal ini dikarenakan penghubung yang digunakan adalah AND
1 Simple selection (simple IF statement)
BalasHapusIF account_balance < $300 THEN
service_charge = $5.00
ELSE
service_charge = $2.00
ENDIF
2.Simple selection with null false branch (null ELSE statement)
IF student_attendance = part_time THEN
add 1 to part_time_count
ENDIF
3. Combined selection (combined IF statement)
Ada 2 LOGIKA yaitu memakai AND dan OR,
contoh memakai AND
IF student_attendance = part_time
AND student_gender = female THEN
add 1 to fem_part_time_count
ENDIF
CONTOH MEMAKAI OR
If student_attendance = part_time
OR student_gender = female THEN
add 1 to fem_part_time_count
ENDIF
4 Nested selection (nested IF statement)
IF record_code = 'A' THEN
increment counter_A
ELSE
IF record_code = 'B' THEN
increment counter_B
ELSE
IF record_code = 'C' THEN
increment counter_C
ELSE
increment error_counter
ENDIF
ENDIF
ENDIF
5.NON LINEAR IF STATMENT
IF student_attendance = part_time THEN
IF student_gender = female THEN
IF student_age > 21 THEN
add 1 to mature_fem_pt_students
ELSE
add 1 to young_fem_pt_students
ENDIF
ELSE
add 1 to male_pt_students
ENDIF
ELSE
add 1 to full_time_students
ENDIF
Saya absen aja ya pak...
BalasHapusterima kasih...
Eka Yuliani/093330740/904
BalasHapusA. Simple Selection :
If Hari = 1 Then
Cetak "Senin"
Else
Cetak "Bukan Hari Senin"
End If
B. Simple Selection Tanpa Cabang :
If Student_atterdance = part_time Then
add 1 to part_time_count
End If
C. Combined Selection :
If Record_Code = '23'
Or update_code = delete
And account_balance = zero Then
delete customer record
End If
D. Nested Selection (Linear If Statments) :
If the age is greater than or equal to 18
get the rigistration status
If the rigistration status is Y
display "You Can Vote"
Else
display "You Need To Register Before you can vote"
End If
Else
display "you are too young to vote"
End If
E. Non Linear :
If code_entered = 111 then
grant_full_access = true
Else
If code_entered = 222 then
grant_restricted_access = True
Else
If code_entered = 333 then
print "No access"
End If
End If
End If
TES
BalasHapus# Simple Selection
BalasHapusIF Gaji > 1200000 THEN
Write "Kena Pajak"
ELSE
Write "Tidak kena pajak"
END IF
# Simple Selection Tanpa Cabang
IF Gaji > 1200000 THEN
Pajak = Gaji*0.25
END IF
# Combined Selection
IF Gaji > 1200000 and kode=1 THEN
Pajak = Gaji*0.25
ELSE
Pajak = Gaji*0.25
END IF
# Nested selection
IF record_code = "1" THEN
increment counter_1
ELSE
IF record_code = "2" THEN
increment counter_2
ELSE
IF record_code = "3" THEN
increment counter_3
ELSE
increment error_counter
END IF
END IF
END IF
# Non Linear IF Statement
IF mahasiswa_laksi = menyusun_TA THEN
if mahasiswa_sks>160 THEN
add 1 to mature_160 sks_menyusun TA_mahasiswa
ELSE
add 1 to small_160 sks_menyusun TA
END IF
ELSE
add 1 to sks_160 sks_mahasiswa
END IF
ELSE
add 1 to full_study_mahasis
END IF
1.simple selection
BalasHapusif saldo<$200 then
bunga = 0.02
else
bunga = 0.1
end if
2.Simple selection tanpa cabang
if saldo >&200 then
bunga = saldo *0.1
end if
3. combined selection
if saldo >200 and code = 2 then
bunga = 0.1
else
bunga = saldo *0.02
end if
statment bunga = saldo *0.1 akan bisa dikerjakan jika kedua kondisi yaitu saldo>200 dan kode = 2 bernilai TRUE.hal ini dikarenakan penghubungan yang digunakan adalah AND
4.Nested selection
if.record_code = 'C' then
increment counter _ C
else
if.record_code = 'D' then
increment counter _ D
else
if.record_code = 'E'
increment counter _ E
else
increment error _ counter
end if
end if
end if
5.non linier nested
if police _attendence = part_time then
if police_gender = female then
if police_age >50 then
add 1 to math_female_PT_police
else
add 1 to old_female_pt_police
end if
add 1 to male_pt_police
add 1 to full_time
maaf saya kurang paham....hanya ini yg bisa saya lakukan ..... :)))
Assalamualaikum....
BalasHapusHandy in here 093330742
1. Contoh Simple Selection, contoh:
BalasHapusIF saldo < $500 THEN
bunga = 0.08
ELSE
bunga = 0.4
ENDIF
2. Simple Selection Tanpa Cabang, contoh:
IF Saldo > $500 THEN
bunga = saldo * 0.4
ENDIF
3. Combined Selection, Contoh:
IF saldo > 500 AND kode = 1 THEN
bunga = saldo * 0.4
ELSE
bunga = saldo * 0.05
ENDIF
4. Nested Selection, Contoh:
IF record_code=‘A’ THEN
increment counter_A
ELSE
IF record_code=‘B’ THEN
increment counter_B
ELSE
IF record_code=‘C’ THEN
increment counter _C
ELSE
increment error_counter
ENDIF
ENDIF
ENDIF
5. Non-Linear Nested IF, Contoh
IF student_attendance=part_time THEN
IF student_gender=female THEN
IF student_age >21 THEN
add 1 to mature_fem_pt_students
ELSE
add 1 to young_fem_pt_students
ENDIF
ELSE
add 1 to male_pt_students
ENDIF
ELSE
add 1 to full_time_students
ENDIF
absen ya pak.. maav baru ol. jd baru absen..
BalasHapusdella dwi jayanti_093330692