While, do while, break, continue Dr. Anto Satriyo Nugroho, M.Eng Web: Mata Kuliah: Dasar.

Presentation on theme: "While, do while, break, continue Dr. Anto Satriyo Nugroho, M.Eng Web: Mata Kuliah: Dasar."— Presentation transcript:

while, do while, break, continue Dr. Anto Satriyo Nugroho, M.Eng Email: asnugroho@gmail.com Web: http://asnugroho.net/lecture/dp.html Mata Kuliah: Dasar Pemrograman

Instruksi while Cara penulisan while (expression)statement; Contoh: #include main() { int no; printf(“tuliskan sebarang bilangan bulat positif: “); scanf(“%d”, &no); while( no >= 0) { printf(“%d “,no); no--; } printf(“\n”); } expr Ya Tidak statement

Instruksi do while Cara penulisan do statement while (expression); expr Ya Tidak statement

Break & Continue Continue #include main() { int i; for(i=0;i<10;i++) { if(i==5) continue; printf(“%d\n”,i); } Hasil: 0 1 2 3 4 6 7 8 9

Break & Continue Break #include main() { int i; for(i=0;i<10;i++) { if(i==5) break; printf(“%d\n”,i); } Hasil: 0 1 2 3 4

Contoh Pemakaian Soal: Buatlah program untuk mencari semua bilangan prima di bawah 1000 Jawab #include { int i,no; for(no=2;no<1000;no++) { for(i=2;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/8/2349851/slides/slide_6.jpg", "name": "Contoh Pemakaian Soal: Buatlah program untuk mencari semua bilangan prima di bawah 1000 Jawab #include { int i,no; for(no=2;no<1000;no++) { for(i=2;i

Download ppt "While, do while, break, continue Dr. Anto Satriyo Nugroho, M.Eng Web: Mata Kuliah: Dasar."

Similar presentations