SlideShare a Scribd company logo
Adam Mukharil Bachtiar
English Class
Informatics Engineering 2011
Algorithms and Programming
Looping Structure
Steps of the Day
Let’s Start
For Structure While Do
Structure
Repeat Until
Structure
WhyWeNeedLooping
Structure?
Make a program to showing “I LOVE
ALGORITHM” on the screen as much as 1000
times. WHAT WILL YOU DO?
WhatisLoopingStructure
An Algorithm structure that allow us to REPEAT
some statements that fulfill LOOPING CONDITION.
ComponentsinLooping
Structure
• Looping condition
• Body statement
• Initialization
• Termination
TypesofLoopingStructure
• FOR
• WHILE
• REPEAT
For Structure
Definition and Structures of For Structure
ForStructure
• For structure was used in looping that have
specified ending of repetition.
• Number of repetition have been known in
the beginning.
• Can be in ASCENDING or DESCENDING way
Format of For Structure (Ascending)
Algorithm Notation:
for variable  start_value to end_value do
statement
endfor
Pascal Notation I:
for variable := start_value to end_value do
statement;
Format of For Structure (Ascending)
Pascal Notation II:
for variable := start_value to end_value do
begin
statement;
end;
Algorithm and Programming (Looping Structure)
Example of For in Ascending Way (Algorithm)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Algoritma Deret_Bilangan_Ganjil
{I.S: Diinputkan satu nilai akhir oleh user}
{F.S: Menampilkan jumlah deret ganjil}
Kamus:
x,akhir:integer
jumlah:integer
Algoritma:
input(akhir)
jumlah  0
for x  1 to akhir do
if x mod 2 = 1 then
jumlah  jumlah + x;
endfor
output(‘Jumlah deret ganjil dari 1 – ‘,akhir,’ = ‘,jumlah)
Example of For in Ascending Way (Pascal)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
program Deret_Bilangan_Ganjil;
uses crt;
var
x,akhir:integer;
jumlah:integer;
begin
write('Masukan batas akhir angka : ');readln(akhir);
jumlah:=0;
for x:=1 to akhir do
begin
if x mod 2=1 then
jumlah:=jumlah+x;
end;
writeln('Jumlah Deret ganjil dari 1 - ',akhir,' = ',jumlah);
writeln();
write('Tekan sembarang tombol untuk menutup...');
readkey();
end.
Format of For Structure (Descending)
Algorithm Notation:
for variable  end_value downto start_value do
statement
endfor
Pascal Notation I:
for variable := end_value downto start_value do
statement;
Format of For Structure (Ascending)
Pascal Notation II:
for variable := end_value downto start_value do
begin
statement;
end;
Algorithm and Programming (Looping Structure)
Example of For in Descending Way (Algorithm)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Algoritma Deret_Faktorial
{I.S: Diinputkan satu nilai oleh user}
{F.S: Menampilkan faktorial dari bilangan tersebut}
Kamus:
i,nilai:integer
faktorial:integer
Algoritma:
input(nilai)
faktorial1
for i  nilai downto 1 do
faktorialfaktorial*i
endfor
output(nilai,’! = ‘,faktorial)
Example of For in Descending Way (Pascal)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
program Deret_Faktorial;
uses crt;
var
i,nilai:integer;
faktorial:integer;
begin
write('Masukan nilai = ');readln(nilai);
faktorial:=1;
for i:=nilai downto 1 do
faktorial:=faktorial*i;
writeln(nilai,'! = ',faktorial);
writeln();
write('Tekan sembarang tombol untuk menutup...');
readkey();
end.
While Structure
Definition and Structures of For Structure
WhileStructure
• While structure always be executed while its
condition value is true.
• If the condition value is false, it means stop
repetition.
• While structure have condition in the
beginning of structure.
Format of While Structure
Algorithm Notation:
while kondisi do
statement
endwhile
Pascal Notation I:
while kondisi do
statement;
Format of While Structure
Pascal Notation II:
while kondisi do
begin
statement;
end;
Algorithm and Programming (Looping Structure)
Example of While (Algorithm)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Algoritma Deret_Bilangan
{I.S: Diinputkan satu angka oleh user}
{F.S: Menampilkan jumlah deret dari 1 sampai angka}
Kamus:
i,deret:integer
angka:integer
Algoritma:
input(angka)
deret0
i1
while i<=angka do
deretderet+i
ii+1;
endwhile
output(‘Jumlah deret dari 1 – ‘,angka,’ = ‘,deret)
Example of While (Pascal)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
program Deret_Angka;
uses crt;
var
i,deret:integer;
angka:integer;
begin
write('Masukan angka = ');readln(angka);
deret:=0;
i:=1;
while i<=angka do
begin
deret:=deret+i;
i:=i+1;
end;
writeln('Jumlah deret dari 1 - ',angka,' = ',deret);
writeln();
write('Tekan sembarang tombol untuk menutup...');
readkey();
end.
Repeat Structure
Definition and Structures of For Structure
RepeatStructure
• Repeat structure always be executed until its
condition value is true.
• If the condition value is true, it means stop
repetition.
• Repeat structure have condition in the end
of structure.
Format of While Structure
Algorithm Notation:
repeat
statement
until kondisi
Pascal Notation:
repeat
statement;
until kondisi;
Algorithm and Programming (Looping Structure)
Example of Repeat (Algorithm)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Algoritma Coba_Password
{I.S: Diinputkan password oleh user}
{F.S: Menampilkan pesan benar atau salah}
Kamus:
const
password=1234
pass,i,j:integer
Algoritma:
i1
j3
repeat
input(pass)
if pass=password then
output(‘Password anda benar!’);
else
ii+1
jj-1
output(‘Password salah (‘,j,’ kali lagi)!’)
endif
until (pass=password)or(i=4)
Example of Repeat (Pascal)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
21
22
23
24
25
26
27
28
29
30
31
32
program Coba_Password;
uses crt;
const
password=1234;
var
pass,i,j:integer;
begin
i:=1;
j:=3;
repeat
write('Masukan password (',i,'): ');readln(pass);
if pass=password then
begin
writeln('Password anda benar!');
writeln();
writeln('Tekan sembarang tombol untuk menutup...');
readkey();
end
else
begin
i:=i+1;
j:=j-1;
writeln('Password salah (',j,' kali lagi)!');
readkey();
end;
clrscr();
until (pass=password)or(i=4);
end.
EXERCISE
Exercise 1
Make the algorithm to solve this problem below (Color of
stars will be different each row):
N=5
*
* *
* * *
* * * *
* * * * *
Exercise 2
Make the algortihm to solve this problem below (Color of
stars will be different each row):
N=3
*
* *
* * *
* *
*
Exercise 3
Make algorithm to count:
s = 1 – 2/3 + 3/5 – 4/7+….
Exercise 4
Make algorithm to count the maximum value and
mean value from n students.
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 (20)

PPTX
Loops in c language
tanmaymodi4
 
PPTX
Control statements in c
Sathish Narayanan
 
PDF
Algorithmic problem sloving
Mani Kandan
 
DOC
Arrays and Strings
Dr.Subha Krishna
 
PDF
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
PPTX
Structure in c language
sangrampatil81
 
PDF
Function in C
Dr. Abhineet Anand
 
PPTX
polymorphism
Imtiaz Hussain
 
PPTX
Operators and expressions in c language
tanmaymodi4
 
PPTX
Inheritance in JAVA PPT
Pooja Jaiswal
 
PPTX
Unit 6. Arrays
Ashim Lamichhane
 
PDF
Formal Languages and Automata Theory unit 5
Srimatre K
 
PPT
Functions in C++
Nikhil Pandit
 
PDF
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
PPTX
Presentation on function
Abu Zaman
 
PDF
Input and Output
Jason J Pulikkottil
 
PPT
String c
thirumalaikumar3
 
PPTX
C Programming: Control Structure
Sokngim Sa
 
PPTX
Basic Input and Output
Nurul Zakiah Zamri Tan
 
DOCX
C programming tutorial
Mohit Saini
 
Loops in c language
tanmaymodi4
 
Control statements in c
Sathish Narayanan
 
Algorithmic problem sloving
Mani Kandan
 
Arrays and Strings
Dr.Subha Krishna
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Structure in c language
sangrampatil81
 
Function in C
Dr. Abhineet Anand
 
polymorphism
Imtiaz Hussain
 
Operators and expressions in c language
tanmaymodi4
 
Inheritance in JAVA PPT
Pooja Jaiswal
 
Unit 6. Arrays
Ashim Lamichhane
 
Formal Languages and Automata Theory unit 5
Srimatre K
 
Functions in C++
Nikhil Pandit
 
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Presentation on function
Abu Zaman
 
Input and Output
Jason J Pulikkottil
 
C Programming: Control Structure
Sokngim Sa
 
Basic Input and Output
Nurul Zakiah Zamri Tan
 
C programming tutorial
Mohit Saini
 

Viewers also liked (17)

PDF
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Adam Mukharil Bachtiar
 
PDF
Algorithm and Programming (Sequential Structure)
Adam Mukharil Bachtiar
 
PDF
Php & mysql course syllabus
Papitha Velumani
 
PPT
Control structures repetition
Online
 
PDF
Algorithm and Programming (Procedure and Function)
Adam Mukharil Bachtiar
 
PPT
Fil11 -mga tungkulin ng wika (1)
University of Santo Tomas
 
PPTX
Looping and switch cases
MeoRamos
 
PDF
Data Management (Data Mining Klasifikasi)
Adam Mukharil Bachtiar
 
PDF
Algorithm and Programming (Branching Structure)
Adam Mukharil Bachtiar
 
PDF
Algorithm and Programming (Record)
Adam Mukharil Bachtiar
 
PPSX
Algorithm and Programming (Sorting)
Adam Mukharil Bachtiar
 
PPSX
Algorithm and Programming (Searching)
Adam Mukharil Bachtiar
 
PDF
Algorithm and Programming (Array)
Adam Mukharil Bachtiar
 
PDF
Algorithm and Programming (Introduction of Algorithms)
Adam Mukharil Bachtiar
 
PPT
Ang Tungkulin Ng Wika
Persia
 
PPT
C++ programming
viancagerone
 
PDF
Writing algorithms
Krishna Chaytaniah
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Adam Mukharil Bachtiar
 
Algorithm and Programming (Sequential Structure)
Adam Mukharil Bachtiar
 
Php & mysql course syllabus
Papitha Velumani
 
Control structures repetition
Online
 
Algorithm and Programming (Procedure and Function)
Adam Mukharil Bachtiar
 
Fil11 -mga tungkulin ng wika (1)
University of Santo Tomas
 
Looping and switch cases
MeoRamos
 
Data Management (Data Mining Klasifikasi)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Branching Structure)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Record)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Sorting)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Searching)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Array)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Introduction of Algorithms)
Adam Mukharil Bachtiar
 
Ang Tungkulin Ng Wika
Persia
 
C++ programming
viancagerone
 
Writing algorithms
Krishna Chaytaniah
 
Ad

Similar to Algorithm and Programming (Looping Structure) (14)

PDF
Control structures c2 c3
Omar Al-Sabek
 
PPT
Algoritma 1 pertemuan 6
adekurnia solihin
 
PPT
Control structures ii
Ahmad Idrees
 
DOCX
Tugas3
Av Ri
 
PDF
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
Sowmya Jyothi
 
PDF
Programming paradigms c1
Omar Al-Sabek
 
PPT
04 control structures 1
Jomel Penalba
 
PPS
02 ds and algorithm session_02
yogeshjoshi362
 
PPS
02 ds and algorithm session_02
Niit Care
 
PDF
Tugas alpro
Welman Munthe
 
PPTX
Algoritma pemrograman 12
ZainalAbidin909479
 
PPT
Repetition Structure
PRN USM
 
PPT
Conditional Loops Python
primeteacher32
 
PPT
ch8.ppt
FakhriAlamKhan1
 
Control structures c2 c3
Omar Al-Sabek
 
Algoritma 1 pertemuan 6
adekurnia solihin
 
Control structures ii
Ahmad Idrees
 
Tugas3
Av Ri
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
Sowmya Jyothi
 
Programming paradigms c1
Omar Al-Sabek
 
04 control structures 1
Jomel Penalba
 
02 ds and algorithm session_02
yogeshjoshi362
 
02 ds and algorithm session_02
Niit Care
 
Tugas alpro
Welman Munthe
 
Algoritma pemrograman 12
ZainalAbidin909479
 
Repetition Structure
PRN USM
 
Conditional Loops Python
primeteacher32
 
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
 

Recently uploaded (20)

PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Import Data Form Excel to Tally Services
Tally xperts
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 

Algorithm and Programming (Looping Structure)

  • 1. Adam Mukharil Bachtiar English Class Informatics Engineering 2011 Algorithms and Programming Looping Structure
  • 2. Steps of the Day Let’s Start For Structure While Do Structure Repeat Until Structure
  • 3. WhyWeNeedLooping Structure? Make a program to showing “I LOVE ALGORITHM” on the screen as much as 1000 times. WHAT WILL YOU DO?
  • 4. WhatisLoopingStructure An Algorithm structure that allow us to REPEAT some statements that fulfill LOOPING CONDITION.
  • 5. ComponentsinLooping Structure • Looping condition • Body statement • Initialization • Termination
  • 7. For Structure Definition and Structures of For Structure
  • 8. ForStructure • For structure was used in looping that have specified ending of repetition. • Number of repetition have been known in the beginning. • Can be in ASCENDING or DESCENDING way
  • 9. Format of For Structure (Ascending) Algorithm Notation: for variable  start_value to end_value do statement endfor Pascal Notation I: for variable := start_value to end_value do statement;
  • 10. Format of For Structure (Ascending) Pascal Notation II: for variable := start_value to end_value do begin statement; end;
  • 12. Example of For in Ascending Way (Algorithm) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Algoritma Deret_Bilangan_Ganjil {I.S: Diinputkan satu nilai akhir oleh user} {F.S: Menampilkan jumlah deret ganjil} Kamus: x,akhir:integer jumlah:integer Algoritma: input(akhir) jumlah  0 for x  1 to akhir do if x mod 2 = 1 then jumlah  jumlah + x; endfor output(‘Jumlah deret ganjil dari 1 – ‘,akhir,’ = ‘,jumlah)
  • 13. Example of For in Ascending Way (Pascal) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 program Deret_Bilangan_Ganjil; uses crt; var x,akhir:integer; jumlah:integer; begin write('Masukan batas akhir angka : ');readln(akhir); jumlah:=0; for x:=1 to akhir do begin if x mod 2=1 then jumlah:=jumlah+x; end; writeln('Jumlah Deret ganjil dari 1 - ',akhir,' = ',jumlah); writeln(); write('Tekan sembarang tombol untuk menutup...'); readkey(); end.
  • 14. Format of For Structure (Descending) Algorithm Notation: for variable  end_value downto start_value do statement endfor Pascal Notation I: for variable := end_value downto start_value do statement;
  • 15. Format of For Structure (Ascending) Pascal Notation II: for variable := end_value downto start_value do begin statement; end;
  • 17. Example of For in Descending Way (Algorithm) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Algoritma Deret_Faktorial {I.S: Diinputkan satu nilai oleh user} {F.S: Menampilkan faktorial dari bilangan tersebut} Kamus: i,nilai:integer faktorial:integer Algoritma: input(nilai) faktorial1 for i  nilai downto 1 do faktorialfaktorial*i endfor output(nilai,’! = ‘,faktorial)
  • 18. Example of For in Descending Way (Pascal) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 program Deret_Faktorial; uses crt; var i,nilai:integer; faktorial:integer; begin write('Masukan nilai = ');readln(nilai); faktorial:=1; for i:=nilai downto 1 do faktorial:=faktorial*i; writeln(nilai,'! = ',faktorial); writeln(); write('Tekan sembarang tombol untuk menutup...'); readkey(); end.
  • 19. While Structure Definition and Structures of For Structure
  • 20. WhileStructure • While structure always be executed while its condition value is true. • If the condition value is false, it means stop repetition. • While structure have condition in the beginning of structure.
  • 21. Format of While Structure Algorithm Notation: while kondisi do statement endwhile Pascal Notation I: while kondisi do statement;
  • 22. Format of While Structure Pascal Notation II: while kondisi do begin statement; end;
  • 24. Example of While (Algorithm) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Algoritma Deret_Bilangan {I.S: Diinputkan satu angka oleh user} {F.S: Menampilkan jumlah deret dari 1 sampai angka} Kamus: i,deret:integer angka:integer Algoritma: input(angka) deret0 i1 while i<=angka do deretderet+i ii+1; endwhile output(‘Jumlah deret dari 1 – ‘,angka,’ = ‘,deret)
  • 25. Example of While (Pascal) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 program Deret_Angka; uses crt; var i,deret:integer; angka:integer; begin write('Masukan angka = ');readln(angka); deret:=0; i:=1; while i<=angka do begin deret:=deret+i; i:=i+1; end; writeln('Jumlah deret dari 1 - ',angka,' = ',deret); writeln(); write('Tekan sembarang tombol untuk menutup...'); readkey(); end.
  • 26. Repeat Structure Definition and Structures of For Structure
  • 27. RepeatStructure • Repeat structure always be executed until its condition value is true. • If the condition value is true, it means stop repetition. • Repeat structure have condition in the end of structure.
  • 28. Format of While Structure Algorithm Notation: repeat statement until kondisi Pascal Notation: repeat statement; until kondisi;
  • 30. Example of Repeat (Algorithm) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Algoritma Coba_Password {I.S: Diinputkan password oleh user} {F.S: Menampilkan pesan benar atau salah} Kamus: const password=1234 pass,i,j:integer Algoritma: i1 j3 repeat input(pass) if pass=password then output(‘Password anda benar!’); else ii+1 jj-1 output(‘Password salah (‘,j,’ kali lagi)!’) endif until (pass=password)or(i=4)
  • 31. Example of Repeat (Pascal) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 30 31 32 program Coba_Password; uses crt; const password=1234; var pass,i,j:integer; begin i:=1; j:=3; repeat write('Masukan password (',i,'): ');readln(pass); if pass=password then begin writeln('Password anda benar!'); writeln(); writeln('Tekan sembarang tombol untuk menutup...'); readkey(); end else begin i:=i+1; j:=j-1; writeln('Password salah (',j,' kali lagi)!'); readkey(); end; clrscr(); until (pass=password)or(i=4); end.
  • 33. Exercise 1 Make the algorithm to solve this problem below (Color of stars will be different each row): N=5 * * * * * * * * * * * * * * *
  • 34. Exercise 2 Make the algortihm to solve this problem below (Color of stars will be different each row): N=3 * * * * * * * * *
  • 35. Exercise 3 Make algorithm to count: s = 1 – 2/3 + 3/5 – 4/7+….
  • 36. Exercise 4 Make algorithm to count the maximum value and mean value from n students.
  • 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