SlideShare a Scribd company logo
Adam Mukharil Bachtiar
English Class
Informatics Engineering 2011
Algorithms and Programming
Branching Structure
Steps of the Day
Let’s Start
Definition Types of
Branching
Case Structure
Definition
Definition of Branching Structure
DefinitionofBranching
Structure
Algorithm structure which allow to execute
the instruction if the condition of this
instruction was met.
UsageofBranchingStructure
• Make menu structure
• Input validation
• Error handling
Types of Branching
Structure
All about Branching Structure
TypesofBranchingStructure
• One Case Branching
• Two Cases Branching
• Three/Many Cases Branching
• Many Conditions Branching
One Case Branching
Algorithm Notation:
if condition then
statement
endif
One Case Branching
Pascal Notation (if there’s only one statement):
if condition then
statement;
One Case Branching
Pascal Notation (if there are many statement):
if condition then
begin
statement 1;
statement 2;
end;
Algorithm and Programming (Branching Structure)
Example of One Case Branching (Algorithm)
1
2
3
4
5
6
7
8
9
10
11
12
Algoritma Bilangan_Ganjil
{I.S: Diinputkan satu bilangan oleh user}
{F.S: Menampilkan statement apabila bilangannya ganjil}
Kamus:
bil:integer
Algoritma:
input(bil)
if bil mod 2 = 1 then
output(‘Bilangan ‘,bil,’ adalah bilangan ganjil’)
endif
Example of One Case Branching (Pascal)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
program Bilangan_Ganjil;
uses crt;
var
bil:integer;
begin
write('Masukan sebuah bilangan bulat: ');
readln(bil);
if bil mod 2 = 1 then
writeln('Bilangan ',bil,' adalah bilangan ganjil');
writeln();
writeln('Ketik sembarang tombol untuk menutup...');
readkey();
end.
Two Cases Branching
Algorithm Notation:
if condition then
statement 1
else
statement 2
endif
Two Cases Branching
Pascal Notation (if there’s only one statement):
if condition then
statement 1
else
statement 2;
Two Cases Branching
Pascal Notation (if there are many statement):
if condition then
begin
statement 1;
statement 2;
end
else
begin
statement 3;
statement 4;
end;
Algorithm and Programming (Branching Structure)
Example of Two Cases Branching (Algorithm)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Algoritma Bilangan_Genap_Ganjil
{I.S: Diinputkan satu bilangan oleh user}
{F.S: Menampilkan statement bilangan ganjil atau genap}
Kamus:
bil:integer
Algoritma:
input(bil)
if bil mod 2 = 1 then
output(‘Bilangan ‘,bil,’ adalah bilangan ganjil’)
else
output(‘Bilangan ‘,bil,’ adalah bilangan genap’)
endif
Example of Two Cases Branching (Pascal)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
program Bilangan_Genap_ganjil;
uses crt;
var
bil:integer;
begin
write('Masukkan sebuah bilangan bulat: ');
readln(bil);
if bil mod 2 = 1 then
writeln('Bilangan ',bil,' adalah bilangan ganjil')
else
writeln('Bilangan ',bil,' adalah bilangan genap');
writeln();
writeln('Tekan sembarang tombol untuk menutup...');
readkey();
end.
Three/Many Cases Branching
Algorithm Notation:
if condition 1 then
statement 1
else
if condition 2 then
statement 2
else
if condition 3 then
statement 3
else
statement 4
endif
endif
endif
Three/Many Cases Branching
Pascal Notation (if there’s only one statement):
if condition 1 then
statement 1
else
if condition 2 then
statement 2
else
if condition 3 then
statement 3
else
statement 4;
Three/Many Cases Branching
Pascal Notation (if there are many statement):
if kondisi 1 then
begin
statement 1;
end
else
if kondisi 2 then
begin
statement 2;
end
else
if kondisi 3 then
begin
statement 3;
end
else
begin
statement 4;
end;
Algorithm and Programming (Branching Structure)
Example of Three/Many Cases Branching (Algorithm)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Algoritma Lampu_Lalu_Lintas
{I.S: Diinputkan satu warna lampu oleh user}
{F.S: Menampilkan statement sesuai warna lampu}
Kamus:
warna:string
Algoritma:
input(warna)
if warna = ‘MERAH’ then
output(‘Berhenti!’)
else
if warna = ‘KUNING’ then
output(‘Hati-Hati!’)
else
if warna = ‘HIJAU’ then
output(‘Jalan!’)
else
output(‘Warna salah!’)
endif
endif
endif
Example of Three/Many Cases Branching (Pascal)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
program Lampu_Lalu_Lintas;
uses crt;
var
warna:string;
begin
write('Masukkan sembarang warna: ');
readln(warna);
warna:=upcase(warna); {membuat uppercase}
if warna='MERAH' then
writeln('Berhenti!')
else
if warna='KUNING' then
writeln('Hati-Hati!')
else
if warna='HIJAU' then
writeln('Jalan!')
else
writeln('Warna salah!');
writeln();
writeln('Tekan sembarang tombol untuk menutup...');
readkey();
end.
Many Conditions Branching
• There are several cases which was requested more
than one conditions.
• Problem solving:
 Use AND : if all condition must be fulfilled
 Use OR : if only one condition must be fulfilled.
Algorithm and Programming (Branching Structure)
Example of Many Conditions Branching (Algorithm)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Algoritma Huruf_Konsonan
{I.S: Diinputkan satu huruf oleh user}
{F.S: Menampilkan pesan huruf konsonan jika konsonan}
Kamus:
k:char
Algoritma:
input(k)
if (k≠’a’)and(k≠’i’)and(k≠’u’)and(k≠’e’)and(k≠’o’) then
output(‘Huruf ‘,k,’ adalah huruf konsonan’)
else
output(‘Huruf ‘,k,’ adalah huruf vokal’)
endif
Example of Many Conditions Branching (Pascal)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
program Huruf_Konsonan;
uses crt;
var
k:char;
begin
write('Masukkan satu huruf: ');
readln(k);
k:=lowercase(k);
if (k<>'a')and(k<>'i')and(k<>'u')and(k<>'e')and(k<>'o') then
writeln('Huruf ',k,' adalah huruf konsonan')
else
writeln('Huruf ',k,' adalah huruf vokal');
writeln();
writeln('Tekan sembarang tombol untuk menutup...');
readkey();
end.
Case Structure
All About Case Structure
Case Structure
• Expression could be arithmetics or boolean.
• Expression was produce a constant.
• Value must be ordinal type (char, boolean, and
integer)
• Statement in otherwise will be executed if the other
value aren’t fulfilled.
Case Structure
Algorithm Notation:
case ekspresi
nilai 1 : statement 1
nilai 2 : statement 2
nilai 3 : statement 3
.
.
.
nilai n : statement n
otherwise : statement x
endcase
Case Structure
Pascal Notation:
case ekspresi of
nilai 1 : statement 1;
nilai 2 : statement 2;
nilai 3 : statement 3;
.
.
.
nilai n : statement n;
else statement x;
end;
Algorithm and Programming (Branching Structure)
Example of Case Structure (Algorithm)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Algoritma Ukuran_Baju
{I.S: Diinputkan satu huruf untuk ukuran baju oleh user}
{F.S: Menampilkan arti ukuran baju}
Kamus:
size:char
Algoritma:
input(size)
case size
‘S’:output(‘Kecil’);
‘M’:output(‘Sedang’);
‘L’:output(‘Besar’);
otherwise : output(‘Ukuran salah!’)
endcase
Example of Case Structure (Pascal)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
program Ukuran_Baju;
uses crt;
var
size:char;
begin
write('Masukkan ukuran baju [S/M/L]: ');
readln(size);
size:=upcase(size);
case size of
'S':writeln('Kecil');
'M':writeln('Sedang');
'L':writeln('Besar');
else writeln('Ukuran salah!');
end;
writeln();
writeln('Tekan sembarang tombol untuk menutup...');
readkey();
end.
Contact Person:
Adam Mukharil Bachtiar
Informatics Engineering UNIKOM
Jalan Dipati Ukur Nomor. 112-114 Bandung 40132
Email: adfbipotter@gmail.com
Blog: http://adfbipotter.wordpress.com
Copyright © Adam Mukharil Bachtiar 2011

More Related Content

What's hot (17)

PPTX
C++ decision making
Zohaib Ahmed
 
PPTX
C# Loops
Hock Leng PUAH
 
PPTX
C decision making and looping.
Haard Shah
 
PPTX
Loops in c language
tanmaymodi4
 
PPTX
Storage classes in c language
tanmaymodi4
 
PDF
Pl sql programme
Dhilip Prakash
 
PPTX
Loop control in c++
Debre Tabor University
 
PDF
C++ control structure
bluejayjunior
 
PDF
Data structure scope of variables
Saurav Kumar
 
PPSX
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
PPTX
Storage classes in C
Nitesh Bichwani
 
PPT
Iteration
Liam Dunphy
 
PPT
Control Statements, Array, Pointer, Structures
indra Kishor
 
PPT
C++ programming
viancagerone
 
PPTX
Loops in java script
Ravi Bhadauria
 
PPTX
Storage class in C Language
Nitesh Kumar Pandey
 
PPTX
11 lec 11 storage class
kapil078
 
C++ decision making
Zohaib Ahmed
 
C# Loops
Hock Leng PUAH
 
C decision making and looping.
Haard Shah
 
Loops in c language
tanmaymodi4
 
Storage classes in c language
tanmaymodi4
 
Pl sql programme
Dhilip Prakash
 
Loop control in c++
Debre Tabor University
 
C++ control structure
bluejayjunior
 
Data structure scope of variables
Saurav Kumar
 
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
Storage classes in C
Nitesh Bichwani
 
Iteration
Liam Dunphy
 
Control Statements, Array, Pointer, Structures
indra Kishor
 
C++ programming
viancagerone
 
Loops in java script
Ravi Bhadauria
 
Storage class in C Language
Nitesh Kumar Pandey
 
11 lec 11 storage class
kapil078
 

Viewers also liked (9)

PDF
Algoritma dan flowchart
ismailtelkom
 
DOCX
Pencarian Rute Terpendek Dengan Menggunakan Algoritma Djikstrak
Arinten Hidayat
 
PDF
Project Studi Kasus Toko Langganan Sistem Informasi Akuntansi
Raysha md
 
PDF
Shortest Path Problem: Algoritma Dijkstra
Onggo Wiryawan
 
PPTX
Algoritma pencarian lintasan jalur terpendek
Laili Wahyunita
 
PDF
Jurnal - Muhamad Imam - Aplikasi Pencarian Rute Terpendek Dengan Menggunakan ...
Muhamad Imam
 
PDF
Pengulangan for Algoritma
casnadi
 
PPTX
Algoritma Pemrograman (Flowchart) - Logika dan Algoritma
Ari Septiawan
 
PDF
Pertemuan 1 algoritma pemrograman dan flowchart
iphientcomp
 
Algoritma dan flowchart
ismailtelkom
 
Pencarian Rute Terpendek Dengan Menggunakan Algoritma Djikstrak
Arinten Hidayat
 
Project Studi Kasus Toko Langganan Sistem Informasi Akuntansi
Raysha md
 
Shortest Path Problem: Algoritma Dijkstra
Onggo Wiryawan
 
Algoritma pencarian lintasan jalur terpendek
Laili Wahyunita
 
Jurnal - Muhamad Imam - Aplikasi Pencarian Rute Terpendek Dengan Menggunakan ...
Muhamad Imam
 
Pengulangan for Algoritma
casnadi
 
Algoritma Pemrograman (Flowchart) - Logika dan Algoritma
Ari Septiawan
 
Pertemuan 1 algoritma pemrograman dan flowchart
iphientcomp
 
Ad

More from Adam Mukharil Bachtiar (20)

PDF
Materi 8 - Data Mining Association Rule.pdf
Adam Mukharil Bachtiar
 
PDF
Clean Code - Formatting Code
Adam Mukharil Bachtiar
 
PDF
Clean Code - Clean Comments
Adam Mukharil Bachtiar
 
PDF
Clean Method
Adam Mukharil Bachtiar
 
PDF
Clean Code and Design Pattern - Meaningful Names
Adam Mukharil Bachtiar
 
PDF
Model Driven Software Development
Adam Mukharil Bachtiar
 
PDF
Scrum: How to Implement
Adam Mukharil Bachtiar
 
PDF
Pengujian Perangkat Lunak
Adam Mukharil Bachtiar
 
PDF
Data Mining Clustering
Adam Mukharil Bachtiar
 
PPTX
Data Mining Klasifikasi (Updated 30 Desember 2020)
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Strategi Algoritma Dynamic Programming
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Strategi Algoritma Divide and Conquer
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Strategi Algoritma Greedy
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Penerapan Strategi Algoritma Brute Force
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Strategi Algoritma Brute Force
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Kelas-kelas Dasar Efisiensi Algoritma
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Teorema Notasi Asimptotik
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Notasi Asimptotik
Adam Mukharil Bachtiar
 
PDF
Activity Diagram
Adam Mukharil Bachtiar
 
PDF
UML dan Use Case View
Adam Mukharil Bachtiar
 
Materi 8 - Data Mining Association Rule.pdf
Adam Mukharil Bachtiar
 
Clean Code - Formatting Code
Adam Mukharil Bachtiar
 
Clean Code - Clean Comments
Adam Mukharil Bachtiar
 
Clean Code and Design Pattern - Meaningful Names
Adam Mukharil Bachtiar
 
Model Driven Software Development
Adam Mukharil Bachtiar
 
Scrum: How to Implement
Adam Mukharil Bachtiar
 
Pengujian Perangkat Lunak
Adam Mukharil Bachtiar
 
Data Mining Clustering
Adam Mukharil Bachtiar
 
Data Mining Klasifikasi (Updated 30 Desember 2020)
Adam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Dynamic Programming
Adam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Divide and Conquer
Adam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Greedy
Adam Mukharil Bachtiar
 
Analisis Algoritma - Penerapan Strategi Algoritma Brute Force
Adam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Brute Force
Adam Mukharil Bachtiar
 
Analisis Algoritma - Kelas-kelas Dasar Efisiensi Algoritma
Adam Mukharil Bachtiar
 
Analisis Algoritma - Teorema Notasi Asimptotik
Adam Mukharil Bachtiar
 
Analisis Algoritma - Notasi Asimptotik
Adam Mukharil Bachtiar
 
Activity Diagram
Adam Mukharil Bachtiar
 
UML dan Use Case View
Adam Mukharil Bachtiar
 
Ad

Recently uploaded (20)

PDF
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
PDF
IObit Driver Booster Pro 12.4.0.585 Crack Free Download
henryc1122g
 
PPTX
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
IObit Driver Booster Pro 12.4.0.585 Crack Free Download
henryc1122g
 
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 

Algorithm and Programming (Branching Structure)

  • 1. Adam Mukharil Bachtiar English Class Informatics Engineering 2011 Algorithms and Programming Branching Structure
  • 2. Steps of the Day Let’s Start Definition Types of Branching Case Structure
  • 4. DefinitionofBranching Structure Algorithm structure which allow to execute the instruction if the condition of this instruction was met.
  • 5. UsageofBranchingStructure • Make menu structure • Input validation • Error handling
  • 6. Types of Branching Structure All about Branching Structure
  • 7. TypesofBranchingStructure • One Case Branching • Two Cases Branching • Three/Many Cases Branching • Many Conditions Branching
  • 8. One Case Branching Algorithm Notation: if condition then statement endif
  • 9. One Case Branching Pascal Notation (if there’s only one statement): if condition then statement;
  • 10. One Case Branching Pascal Notation (if there are many statement): if condition then begin statement 1; statement 2; end;
  • 12. Example of One Case Branching (Algorithm) 1 2 3 4 5 6 7 8 9 10 11 12 Algoritma Bilangan_Ganjil {I.S: Diinputkan satu bilangan oleh user} {F.S: Menampilkan statement apabila bilangannya ganjil} Kamus: bil:integer Algoritma: input(bil) if bil mod 2 = 1 then output(‘Bilangan ‘,bil,’ adalah bilangan ganjil’) endif
  • 13. Example of One Case Branching (Pascal) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 program Bilangan_Ganjil; uses crt; var bil:integer; begin write('Masukan sebuah bilangan bulat: '); readln(bil); if bil mod 2 = 1 then writeln('Bilangan ',bil,' adalah bilangan ganjil'); writeln(); writeln('Ketik sembarang tombol untuk menutup...'); readkey(); end.
  • 14. Two Cases Branching Algorithm Notation: if condition then statement 1 else statement 2 endif
  • 15. Two Cases Branching Pascal Notation (if there’s only one statement): if condition then statement 1 else statement 2;
  • 16. Two Cases Branching Pascal Notation (if there are many statement): if condition then begin statement 1; statement 2; end else begin statement 3; statement 4; end;
  • 18. Example of Two Cases Branching (Algorithm) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Algoritma Bilangan_Genap_Ganjil {I.S: Diinputkan satu bilangan oleh user} {F.S: Menampilkan statement bilangan ganjil atau genap} Kamus: bil:integer Algoritma: input(bil) if bil mod 2 = 1 then output(‘Bilangan ‘,bil,’ adalah bilangan ganjil’) else output(‘Bilangan ‘,bil,’ adalah bilangan genap’) endif
  • 19. Example of Two Cases Branching (Pascal) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 program Bilangan_Genap_ganjil; uses crt; var bil:integer; begin write('Masukkan sebuah bilangan bulat: '); readln(bil); if bil mod 2 = 1 then writeln('Bilangan ',bil,' adalah bilangan ganjil') else writeln('Bilangan ',bil,' adalah bilangan genap'); writeln(); writeln('Tekan sembarang tombol untuk menutup...'); readkey(); end.
  • 20. Three/Many Cases Branching Algorithm Notation: if condition 1 then statement 1 else if condition 2 then statement 2 else if condition 3 then statement 3 else statement 4 endif endif endif
  • 21. Three/Many Cases Branching Pascal Notation (if there’s only one statement): if condition 1 then statement 1 else if condition 2 then statement 2 else if condition 3 then statement 3 else statement 4;
  • 22. Three/Many Cases Branching Pascal Notation (if there are many statement): if kondisi 1 then begin statement 1; end else if kondisi 2 then begin statement 2; end else if kondisi 3 then begin statement 3; end else begin statement 4; end;
  • 24. Example of Three/Many Cases Branching (Algorithm) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Algoritma Lampu_Lalu_Lintas {I.S: Diinputkan satu warna lampu oleh user} {F.S: Menampilkan statement sesuai warna lampu} Kamus: warna:string Algoritma: input(warna) if warna = ‘MERAH’ then output(‘Berhenti!’) else if warna = ‘KUNING’ then output(‘Hati-Hati!’) else if warna = ‘HIJAU’ then output(‘Jalan!’) else output(‘Warna salah!’) endif endif endif
  • 25. Example of Three/Many Cases Branching (Pascal) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 program Lampu_Lalu_Lintas; uses crt; var warna:string; begin write('Masukkan sembarang warna: '); readln(warna); warna:=upcase(warna); {membuat uppercase} if warna='MERAH' then writeln('Berhenti!') else if warna='KUNING' then writeln('Hati-Hati!') else if warna='HIJAU' then writeln('Jalan!') else writeln('Warna salah!'); writeln(); writeln('Tekan sembarang tombol untuk menutup...'); readkey(); end.
  • 26. Many Conditions Branching • There are several cases which was requested more than one conditions. • Problem solving:  Use AND : if all condition must be fulfilled  Use OR : if only one condition must be fulfilled.
  • 28. Example of Many Conditions Branching (Algorithm) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Algoritma Huruf_Konsonan {I.S: Diinputkan satu huruf oleh user} {F.S: Menampilkan pesan huruf konsonan jika konsonan} Kamus: k:char Algoritma: input(k) if (k≠’a’)and(k≠’i’)and(k≠’u’)and(k≠’e’)and(k≠’o’) then output(‘Huruf ‘,k,’ adalah huruf konsonan’) else output(‘Huruf ‘,k,’ adalah huruf vokal’) endif
  • 29. Example of Many Conditions Branching (Pascal) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 program Huruf_Konsonan; uses crt; var k:char; begin write('Masukkan satu huruf: '); readln(k); k:=lowercase(k); if (k<>'a')and(k<>'i')and(k<>'u')and(k<>'e')and(k<>'o') then writeln('Huruf ',k,' adalah huruf konsonan') else writeln('Huruf ',k,' adalah huruf vokal'); writeln(); writeln('Tekan sembarang tombol untuk menutup...'); readkey(); end.
  • 30. Case Structure All About Case Structure
  • 31. Case Structure • Expression could be arithmetics or boolean. • Expression was produce a constant. • Value must be ordinal type (char, boolean, and integer) • Statement in otherwise will be executed if the other value aren’t fulfilled.
  • 32. Case Structure Algorithm Notation: case ekspresi nilai 1 : statement 1 nilai 2 : statement 2 nilai 3 : statement 3 . . . nilai n : statement n otherwise : statement x endcase
  • 33. Case Structure Pascal Notation: case ekspresi of nilai 1 : statement 1; nilai 2 : statement 2; nilai 3 : statement 3; . . . nilai n : statement n; else statement x; end;
  • 35. Example of Case Structure (Algorithm) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Algoritma Ukuran_Baju {I.S: Diinputkan satu huruf untuk ukuran baju oleh user} {F.S: Menampilkan arti ukuran baju} Kamus: size:char Algoritma: input(size) case size ‘S’:output(‘Kecil’); ‘M’:output(‘Sedang’); ‘L’:output(‘Besar’); otherwise : output(‘Ukuran salah!’) endcase
  • 36. Example of Case Structure (Pascal) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 program Ukuran_Baju; uses crt; var size:char; begin write('Masukkan ukuran baju [S/M/L]: '); readln(size); size:=upcase(size); case size of 'S':writeln('Kecil'); 'M':writeln('Sedang'); 'L':writeln('Besar'); else writeln('Ukuran salah!'); end; writeln(); writeln('Tekan sembarang tombol untuk menutup...'); readkey(); end.
  • 37. Contact Person: Adam Mukharil Bachtiar Informatics Engineering UNIKOM Jalan Dipati Ukur Nomor. 112-114 Bandung 40132 Email: [email protected] Blog: http://adfbipotter.wordpress.com Copyright © Adam Mukharil Bachtiar 2011