algoritma dan pemrograman c++ (control structure)
DESCRIPTION
TRANSCRIPT
ALGORITMADAN PEMROGRAMAN 1Semester Ganjil 2013 - 2014
C++ Control Structure
Beni Suranto, S.T., M.SoftEng
Software & References
• IDE: Codeblocks
http://www.codeblocks.org/downloads
• Tutorial:
http://www.cprogramming.com/tutorial/c++-tutorial.html
http://www.cplusplus.com/doc/tutorial/
Selection in C++
if (x < 0)cout << “Bilangan Negatif”;
Selection in C++
if (x < 0){
cout << “Bilangan negatif” << endl ;}
Selection in C++
if (x < 0){
cout << “Bilangan negatif” << endl ;} else {
cout << “Bilangan positif” << endl ;}
Selection in C++
if (x < 0){
cout << “Bilangan negatif” << endl ;} else if (x == 0){
cout << “Nol” << endl ;} else {
cout << “Bilangan positif” << endl ;}
Loop/Iteration in C++
while (x < 10){
cout << x << endl ;x = x + 1;
}
Loop/Iteration in C++
do{
cout << x << endl ;x = x + 1;
} while(x < 10);
break statement in C++
while(x < 10){
cout << x << endl;x = x + 1;if(x == 7) break;
}
Menghentikan/ keluar dari proses perulangan
Pada perulangan disamping, pada saatnilai x sama dengan7 maka perulanganakan dihentikan.
continue statement in C++
while(x < 10){
if(x == 7) {
x = x + 1;continue;
}cout << x << endl;x = x + 1;
}
skip/ lompat pada proses perulangan
Pada perulangan disamping, pada saatnilai x sama dengan7 maka 2 statement terakhir tidakdieksekusi, langsunglompat ke iterasiberikutnya (nilai 7 tidak dicetak)
Terima kasih..