# Logical – IF – CASE OF

Referensi Algo 2 (Pascal)
```1: Program Tutorial2_if;
2: var pilih: Integer;
3: Begin
4:   write('Pilih 1 atau 2'); readln(pilih);
5:   if pilih=1 then write('Anda memilih 1')
6:   elseif pilih=2 then write('Pilihan anda 2')
7:   else write('Anda memilih yang lain');
8: End.

1: Program Tutorial2_case;
2: var pilih: char;
3: Begin
4:   write('Pilih 1 atau 2'); readln(pilih);
5:   case pilih of
6:     '1': write('Anda memilih 1');
7:     '2': write('Pilihan anda 2');
8:   else write('Anda memilih yang lain');
9:   end;
10: End.

Program CaseOf_Or;
Uses crt;
Var
Hargaperkg:integer;
Kualitas:char;
Begin
Clrscr;
Write(‘ Massukkan Kualitas Buah [A/B/C] : ‘); readln(kualitas);
Case kualitas of
‘A’,’a’: hargaperkg:=1000;
‘B’,’b’: hargaperkg:=750;
‘C’,’c’: hargaperkg:=500;
Else
Hargaperkg:=0;
End;
Writeln(‘ Harga Per Kg : Rp.’,hargaperkg);
End.

Structure Case...Of;```
```(http://www.cise.ufl.edu)

The Simple Case Statement```

So far, you have learned how to use an ‘if statement’. But in some cases the ‘case statement‘ is preferred to the if statement because it reduces some unnecessary code but the same meaning is retained. The case statement is very similar to the if statement, except in that the it does not accept literal conditional expressions (i.e.: strings) but surprisingly enough, it allows single character conditional expressions. Here is how it works:

Case {variable of type: integer or character ONLY} of

{input statement- within inverted commas if of type char} : {code..}

{input statement- within inverted commas if of type char} : {code..}

End; {End Case}

http://pascalprogramming.byethost15.com