Struktur Kendali Pengulangan
Pertemuan 6
Matakuliah : T0456 / Algoritma dan Metode Object
Oriented Programming
Tahun : 2007
Bina Nusantara
Learning Outcomes
Pada akhir pertemuan ini, diharapkan:
Mahasiswa dapat memilih struktur kendali pengulangan yang
tepat dalam membuat program C++
Buku Referensi:
C++ - How to program, Deitel & Deitel,
Prentice Hall, 2001.
Websites:
http://www.deitel.com
3
Bina Nusantara
4
Outline Materi
• Guna Struktur Kendali Pengulangan
• Perintah For
• Perintah Do-while
• Perintah While
• Contoh program
Bina Nusantara
Merupakan fasilitas bahasa C++ yang mampu
melakukan proses pengulangan, karena itu komputer
dapat mengerjakan proses berulang-ulang dengan
cepat, tepat dan tanpa lelah.
Kontruksi pengulangan dalam C++ meliputi :
– perintah for
– perintah do-while
– perintah while
Struktur Pengulangan (Loops)
5
Bina Nusantara
C++ memiliki dua jenis pengulangan for - fixed
dan conditional.
Syntax :
for(<intialisasi variable >; <kondisi>;
<penambahan/pengurangan variable>){
<statement>
...
<statement>
}
Perintah for
6
Bina Nusantara
Perintah for
Contoh :
for ( i = 0; i < 10; i++ )
cout << “ Kuadrat dari “ << i
<< “ = “ << i * i << “ n ”;
7
Bina Nusantara
C++ mengijinkan pembentukan infinite loop / open
loop, dengan menghilangkan ketiga parameter
yang ada pada for loop.
Syntax :
for( ; ; ){
<statement>
...
<statement>
}
Infinite Loop
8
Bina Nusantara
Loop ini dikenal dengan nama conditional loop,
dimana kondisi pengulangan di periksa pada akhir
blok loop.
Syntax :
do {
<sequence of statements>
} while (condition);
Perintah Do-while Loop
9
Bina Nusantara
true
false
action(s)
condition
Flowchart Perintah Do-while Loop
10
Bina Nusantara
Perintah Do-while Loop
Contoh :
int i = 2 ;
do {
cout << i << “ ^2 = “ << i * i << “ n ”;
} while ( ++i < 11 ) ;
11
Bina Nusantara
// Contoh program C++ menggunakan do-while loop
#include <math.h>
void main() {
char c ; double x, y ;
do{
do {
cout << “Masukkan Bilangan: “ ;
cin >> x ;
} while ( x < 0 );
y = sqrt ( x ) ;
cout << “Sqrt(“ << x << “)=“<< y << “n”
<< “Masukkan bilangan lain?(Y/N)”;
cin >> c ;
cout << “ n ” ;
} while ( c == ‘ Y ’ || c == ‘ y ’ );
}
Contoh Program
12
Bina Nusantara
Loop ini juga merupakan conditional loop, dimana
kondisi pengulangan diuji pada awal blok
pengulangan.
Syntax :
while ( condition )
statement { sequence of statement }
Perintah while Loop
13
Bina Nusantara
action(s)
true
false
condition
Flowchart Perintah while Loop
14
Bina Nusantara
Contoh :
int i = 2 ;
while ( ++i < 11 ) {
cout << i << “ ^2 = “ << i * i << “ n ”;
};
Perintah while Loop
15
Bina Nusantara
// Contoh program C++ menggunakan while loop
#include <math.h>
void main() {
char c = ‘y’ ; double x=-1, y;
while ( c == ‘ Y ’ || c == ‘ y ’ ){
while ( x < 0 ) {
cout << “Masukkan Bilangan: “ ;
cin >> x ;
}
y = sqrt ( x );
cout << “Sqrt(“ << x << “)=“<< y << “n”
<< “Masukkan bilangan lain?(Y/N)”;
cin >> c ;
cout << “ n ” ;
}
}
Contoh Program
16
Bina Nusantara
17
Diskusi dan Tanya Jawab
Latihan soal

Struktur Kendali Pengulangan-T045414618-Pert-06.ppt

  • 2.
    Struktur Kendali Pengulangan Pertemuan6 Matakuliah : T0456 / Algoritma dan Metode Object Oriented Programming Tahun : 2007
  • 3.
    Bina Nusantara Learning Outcomes Padaakhir pertemuan ini, diharapkan: Mahasiswa dapat memilih struktur kendali pengulangan yang tepat dalam membuat program C++ Buku Referensi: C++ - How to program, Deitel & Deitel, Prentice Hall, 2001. Websites: http://www.deitel.com 3
  • 4.
    Bina Nusantara 4 Outline Materi •Guna Struktur Kendali Pengulangan • Perintah For • Perintah Do-while • Perintah While • Contoh program
  • 5.
    Bina Nusantara Merupakan fasilitasbahasa C++ yang mampu melakukan proses pengulangan, karena itu komputer dapat mengerjakan proses berulang-ulang dengan cepat, tepat dan tanpa lelah. Kontruksi pengulangan dalam C++ meliputi : – perintah for – perintah do-while – perintah while Struktur Pengulangan (Loops) 5
  • 6.
    Bina Nusantara C++ memilikidua jenis pengulangan for - fixed dan conditional. Syntax : for(<intialisasi variable >; <kondisi>; <penambahan/pengurangan variable>){ <statement> ... <statement> } Perintah for 6
  • 7.
    Bina Nusantara Perintah for Contoh: for ( i = 0; i < 10; i++ ) cout << “ Kuadrat dari “ << i << “ = “ << i * i << “ n ”; 7
  • 8.
    Bina Nusantara C++ mengijinkanpembentukan infinite loop / open loop, dengan menghilangkan ketiga parameter yang ada pada for loop. Syntax : for( ; ; ){ <statement> ... <statement> } Infinite Loop 8
  • 9.
    Bina Nusantara Loop inidikenal dengan nama conditional loop, dimana kondisi pengulangan di periksa pada akhir blok loop. Syntax : do { <sequence of statements> } while (condition); Perintah Do-while Loop 9
  • 10.
  • 11.
    Bina Nusantara Perintah Do-whileLoop Contoh : int i = 2 ; do { cout << i << “ ^2 = “ << i * i << “ n ”; } while ( ++i < 11 ) ; 11
  • 12.
    Bina Nusantara // Contohprogram C++ menggunakan do-while loop #include <math.h> void main() { char c ; double x, y ; do{ do { cout << “Masukkan Bilangan: “ ; cin >> x ; } while ( x < 0 ); y = sqrt ( x ) ; cout << “Sqrt(“ << x << “)=“<< y << “n” << “Masukkan bilangan lain?(Y/N)”; cin >> c ; cout << “ n ” ; } while ( c == ‘ Y ’ || c == ‘ y ’ ); } Contoh Program 12
  • 13.
    Bina Nusantara Loop inijuga merupakan conditional loop, dimana kondisi pengulangan diuji pada awal blok pengulangan. Syntax : while ( condition ) statement { sequence of statement } Perintah while Loop 13
  • 14.
  • 15.
    Bina Nusantara Contoh : inti = 2 ; while ( ++i < 11 ) { cout << i << “ ^2 = “ << i * i << “ n ”; }; Perintah while Loop 15
  • 16.
    Bina Nusantara // Contohprogram C++ menggunakan while loop #include <math.h> void main() { char c = ‘y’ ; double x=-1, y; while ( c == ‘ Y ’ || c == ‘ y ’ ){ while ( x < 0 ) { cout << “Masukkan Bilangan: “ ; cin >> x ; } y = sqrt ( x ); cout << “Sqrt(“ << x << “)=“<< y << “n” << “Masukkan bilangan lain?(Y/N)”; cin >> c ; cout << “ n ” ; } } Contoh Program 16
  • 17.
    Bina Nusantara 17 Diskusi danTanya Jawab Latihan soal

Editor's Notes

  • #5 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.
  • #6 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.
  • #7 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.
  • #8 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.
  • #9 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.
  • #10 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.
  • #11 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.
  • #12 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.
  • #13 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.
  • #14 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.
  • #15 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.
  • #16 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits.