1 / 10

SELEKSI

SELEKSI. IF & CASE. if dengan 1 statement. IF dengan banyak statement. If skor > 8 then Begin Nilai := ‘A’; Lulus :=True; Bonus := 50000; End;. If skor > 8 then Nilai :=‘A’. If-then-else dengan 1 statement. If banyak statement dan else 1statement. If skor > 8 then

Download Presentation

SELEKSI

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SELEKSI IF & CASE

  2. if dengan 1 statement IF denganbanyak statement If skor > 8 then Begin Nilai := ‘A’; Lulus :=True; Bonus := 50000; End; If skor > 8 then Nilai:=‘A’

  3. If-then-else dengan 1 statement If banyak statement dan else 1statement If skor > 8 then Begin Nilai := ‘A’; Lulus := True; Bonus :=40000; End Else nilai :=‘B’; If skor > 8 nilai:=‘A’ Elsenilai:=‘B’;

  4. If dengan 1statement – else banyak statement If-then-else banyak statement If skor > 8 then Begin Nilai := ‘A’; Lulus :=True; Bonus := 50000; End Else begin Nilai := ‘B’; Lulus := false; Bonus :=0; End; If skor > 8 then nilai := ‘A’; Else begin Nilai := ‘B’; Bonus := 40000; End;

  5. If-then-else if If bersarang If skor > 8 then if tugas :=true then if prosentaseabsen > 80 then Nilai:=‘A’; If (skor>8) and tugas:=true and (prosentaseabsen > 80) then nilai ‘A’; If skor > 8 then nilai := ‘A’ Else if skor > 6 then nilai :=‘B’ Else if skor > 4 then nilai :=‘C’else if skor > 2 then nilai :=‘D’ Else nilai:=‘E’;

  6. SELEKSI CASE CASE biasanyadigunakanuntukmemilihdiantaralebihdari 2 pilihan. Case dipakaiuntukmenggantikanstruktur if-else-if dimanakondisinyamengacupadavariabel yang sama. Misalnya…

  7. Case 1 statement Case nilai of 8 : write(‘bagussekali’); 6 : write(‘bagus’); 4 : write(‘jelek’); Else write(‘jeleksekali’); End; If nilai = 8 then status :=‘bagussekali’; Else if nilai = 6 then status:=‘bagus’ Else if nilai = 4 then status:=‘jelek’ Else status:=‘jeleksekali’;

  8. Case banyak statement Case nilai of 8 : Begin Write(‘bagussekali’); write(‘pertahankan’); End; 6 : Begin Write(‘bagus’); write(‘tingkatkan’); End; 4 : Begin Write(‘jelek’); write(‘perbaiki’); End; Else Begin Write(‘jeleksekali’); write(‘perbaikilagi’); End;

  9. Case nilai of 8 : write(‘bagussekali’); 6 : write(‘bagus’); 4 : write(‘jelek’); Else write(‘jeleksekali’); End; CONTOH 1 Program operasi1; Uses wincrt; Varinvalid_operator : boolean; Operator : char; A1, A2, Hasil: real; Begin Invalid_operator:=false; Write(‘masukkan angka1= ‘);Readln(AI); Write(‘masukkan angka2= ‘);Readln(A2); Write(‘masukkan OPERATOR= ‘); Readln(operator); If operator = ‘*’ then Hasil:= angka1*angka2 Else If operator = ‘/’ then Hasil:= angka1/angka2 Else If operator = ‘+’ then Hasil:= angka1+angka2 Else If operator = ‘-’ then Hasil:= angka1-angka2 Else invalid_operator : =TRUE; If invalid_operator then (writeln (‘operator salah’) Else Writeln(angka1:4:2, ‘ ‘ ,operator, ‘ ‘ ,angka2:4:2, ‘ adalah ’ ,hasil:5:2) End.

  10. Program operasi2; Uses wincrt; Varinvalid_operator : boolean; Operator : char; A1, A2, Hasil: real; Begin Invalid_operator:=false; Write(‘masukkan angka1= ‘);Readln(AI); Write(‘masukkan angka2= ‘);Readln(A2); Write(‘masukkan OPERATOR= ‘); Readln(operator); Case operator of ‘*’ : hasil:= angka1 * angka2; ‘/’ : hasil:= angka1 / angka2; ‘+’ : hasil:= angka1 + angka2; ‘-’ : hasil:= angka1 - angka2; Else invalid_operator := True End; If invalid_operator then (writeln (‘operator salah’) Else Writeln(angka1:4:2, ‘ ‘ ,operator, ‘ ‘ ,angka2:4:2, ‘ adalah ’ ,hasil:5:2) End.

More Related