1 / 19

Repetisi

IT-132 Dasar-Dasar Pemrograman. Repetisi. Ramos Somya , S.Kom ., M.Cs. 4 Prinsip Utama dalam Pemrograman. Sequence Procedure & Function Choice Repetition. Repetisi. Looping Iterasi Perulangan

coty
Télécharger la présentation

Repetisi

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IT-132 Dasar-Dasar Pemrograman Repetisi Ramos Somya, S.Kom., M.Cs.

  2. 4PrinsipUtamadalamPemrograman • Sequence • Procedure & Function • Choice • Repetition

  3. Repetisi • Looping • Iterasi • Perulangan • Mengulang suatu perintah yang memiliki aturan yang sama, sehingga mengefisienkan dan memudahkan dalam pemrograman. • Karena penggunaan prosedur tidak mampu menghilangkan sekuens instruksi yang bersifat perulangan atau repetisi dalam suatu program.

  4. Contoh *** *** *** • Dengan Procedure: def r3(p) = p();p();p(); enddef def tiga() = NL; p*;p*;p*; enddef r3(tiga) • Penggunaan repetisi jauh lebih baik terutama jika kita ingin membuat pola yang berbeda.

  5. Format Repetisi (1) Contoh: #### Perintah: times 4 do p#; od times F do P od

  6. #### #### #### times 3 do NL; times 4 do p#; od od

  7. Format Repetisi (2) for n runningthrough 1..5 do { perintah yang diulang } od for n runningbackthrough 5..1 do { perintah yang diulang } od Contoh: *** *** *** Perintah: for n runningthrough 1..3 do { NL; times 3 do p*; od } od

  8. * ** *** **** Perintah: for n runningthrough 1..4 do { NL; times n do p*; od } od

  9. **** *** ** * Perintah: for n rbt 4..1 do { NL; times n do p*; od; } od

  10. NL; times 7 do p*; od for n rt 1..5 do { NL; times n do ps; od; p*; times 5-n do ps; od; p*; } od NL; times 6 do ps; od; p*;

  11. Procedure danrepetisi • Program sebelumnya dapat dibuat lebih dinamis menggunakan procedure dan repetisi: def segitiga (n) = NL; times n do p*; od for i rt 1..n-2 do { NL; times i do ps; od; p*; times n-2-i do ps; od; p*; } od NL; times n-1 do ps; od; p*; enddef

  12. Buat procedure untuk mencetak sebaris k segitiga dengan ukuran nxn. Jarak antar segitiga satu spasi. ??????

  13. • Ada berapa baris?? • Ada berapa segitiga?? Perintah: for n rbt 4..1 do { NL; times 3 do { times 5-n ps; od times n p*; od } od } od

  14. • Modifikasimenjadi n barisdan k kolom. • for n rt 4..1 mencetak 4 baris. • times 3 mencetak 3 segitiga. Prosedure-nya: def segitiga(n, k) = for m rbt n..1 do { NL; times k do { times n+1-m do ps; od times m do p*; od } od } od enddef

  15. Latihan • Buat pola berikut ini dengan perulangan!

  16. * ** *** Bagaimana jika * diganti dengan angka?? Buat perintah dengan perulangan untuk mencetak pola: 1 1 22 12 333 123

  17. for n rt 1..3 do { NL; times n do p(n); od } od for n rt 1..3 do { NL; for m rt 1..n do { p(m); od } od } od

  18. See You Next Week

More Related