Algoritma dan Pemrogramman (4)

Repetition: Instruksi yang diulang beberapa kali. Fungsi-fungsi Repetition:

For:
for(exp1; exp2; exp3) state;

for(exp1; exp2; exp3){
state;
}

Exp 1 = Inisialisasi
Exp 2 = Kondisional (berjalan selama bernilai true (not zero) dan berhenti jika bernilai false (zero))
Exp 3 = Increment/Decrement

While:
while(exp) statement;

while(exp){
statement;
}

Exp = Bool Expression. Akan berjalan selama bernilai true (not zero) dan berhenti jika bernilai false (zero)

Do-While:
do{
statement;
} while (exp);

Statement dijalankan terlebih dahulu baru dicek di fungsi while

break = berfungsi untuk menghentikan looping
continue = berfungsi untuk mengskip looping pada kondisi tersebut

Leave a Reply

Your email address will not be published. Required fields are marked *