Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 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

2 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

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

4 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

5 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

6 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<no;i++) if (no%i == 0) break; if(no==i) printf(“%d\n”,no); }


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

Similar presentations


Ads by Google