9.1 Proses Yang Berulang

Seringkali kita harus melakukan pengulangan terhadap suatu proses. Untuk memudahkan hal ini, turbo pascal menyediakan tiga macam pernyataan :
 FOR,
 WHILE,
 REPEAT.

Dengan menggunakan pernyataan ini, suatu proses yang berulang dapat ditulis dengan kode yang pendek. Sebagai contoh, jika anda diminta menampilkan tulisan “Turbo Pascal” seratus kali, tidaklah mungkin kita menuliskan perintah writeln (‘turbo pascal’) seratus kali. Bila hal ini harus dilakukan karena tidak ada pernyataan lain yang mendukung, pemograman akan terasa membosankan. Untungnya hal ini tidak harus terjadi !
Ketiga pernyataan di atas merupakan komponen yang membuat pascal merupakan suatu bahasa pemograman yang terstruktur. Suatu pengulangan dapat dilakukan tanpa menggunakan pernyataan GOTO sebagaimana dilakukan pada bahasa-bahasa pendahulu pascal (meskipun pascal juga menyediakannya).

Terdapat istilah loop atau kalang. Istilah ini menyatakan proses yang berulang.

9.2 Pernyataan FOR

Pernyataan FOR biasa digunakan untuk melakukan pengulangan yang jumlahnya telah diketahui sebelumnya. Sebagai contoh, FOR dapat digunakan untuk menampilkan tulisan ‘Turbo Pascal’ 10 kali atau pun dalam jumlah yang lebih banyak lagi.

9.2.1 FOR TO
Salah satu bentuk pernyataan FOR adalah sebagai berikut :
FOR variabel := nilai_awal TO nilai_akhir DO
Pernyataan

Gambar 9.1 Pernyataan FOR
Pada format ini,variabel bertindak sebagai variabel pengontrol pengulangan. Variabel akan diisi dengan nilai, dimulai dari nilai_awal hingga nilai_akhir untuk setiap iterasi (putaran). Untuk setiap iterasi, pernyataan akan dijalankan. Gambar 9.1 menunjukkan mekanisme pengulangan oleh FOR.

Pada bentuk FOR diatas :
 Variabel, nilai_akhir dan nilai_awal harus bertipe sama atau kompatibel.
 Tipe yang digunakan pada ketiga komponen tersebut harus berupa ordinal.
 Nilai_awal harus lebih kecil atau sama dengan nilai_akhir. Kalau nilai_akhir lebih kecil dari nilai_awal, bagian pernyataan tidak dijalankan sama sekali.

Contoh program yang menggunakan FOR untuk menampilkan tulisan ‘Turbo Pascal’ 10 kali :
Program 9.1

PROGRAM X10;
{—————————————————– }
{ contoh pemakaian FOR untu }
{ menampilkan tulisan turbo pascal 10 kali.}
{—————————————————– }

Uses crt;
Var
Pencacah: integer ;
Begin
Clrscr;
FOR Pencacah := 1 TO 10 DO
Writeln (‘Turbo Pascal’ );
End.

Akhir Program

Pada contoh diatas, pencacah akan bernilai 1, 2, 3, 4 hingga 10 secara berturut-turut. Untuk setiap nilai tersebut, pernyataan :
Writeln (‘Turbo Pascal’);
Dieksekusi. Sebagai akibatnya, pada layar muncul tulisan :
Turbo Pascal
Sebanyak 10 kali.

Pada contoh berikut, isi variabel pengontrol FOR ditampilkan.
Program 9.2

Program deret;
{———————————————————- }
{ menampilakan bilangan 1 sampai dengan 10 }
{———————————————————– }
Uses crt;
Var
Pencacah : integer;
Begin
Clrscr;
FOR Pencacah := 1 TO 10 DO
Writeln (‘pencacah’);
End.
Akhir Program

Hasilnya berupa bilangan dari 1 sampai dengan 10:
1
2
3
4
5
6
7
8
9
10

Di depan telah dijelaskan bahwa nilai awal yang diberikan pada FOR-TO harus lebih kecil dari nilai akhir. Apa yang terjadi seandainya aturan ini dilanggar ? Marilah kita lihat contoh berikut :
FOR Pencacah := 10 TO 1 DO
Writeln (‘pencacah’);
Perintah seperti diatas tidak menghasilkan keluaran apapun. Anda dapat melihat Gambar 9.1 untuk menganalisis kenapa hasilnya tidak ada.

Sebuah gambaran atas penggunaan pernyataan majemuk didalam pernyataan FOR ditunjukkan pada program berikut :
Program 9.3

Program rata2;
{——————————————————————– }
{ contoh program untuk menghitung nilai rata-rata }
{ dari sejumlah nilai. }
{——————————————————————– }

Uses crt;
Var
Nilai, {menampung data dari keyboard}
Jum : real ; {untuk menampung jumlah semua data}
Pencacah : integer ;
Begin
Clrscr;
Jum :=0; {diisi dengan nol terlebih dahulu}
FOR Pencacah := 1 TO 5 DO
Begin
Write (‘nilai ke-‘, pencacah,’ :’);
Readln (nilai);
Jum := jum + nilai; {tambahkan nilai ke jum }
End;
Writeln(‘nilai rata-rata=’, jum/5 :0:2);
End.

Akhir Program

695 responses »

Comment navigation

  1. sarung tangan bayi mengatakan:

    Wow, incredible blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your website is fantastic, as well as the content!. Thanks For Your article about Proses yang Berulang Pada Pascal | Rumah Radhen .

  2. web-site mengatakan:

    Actually worthwhile article. Spend interest web-site http://www.czolowka.wypozycjonuj.com/tag/ISO web-site

  3. add effects to photos mengatakan:

    Yahoo results

    While searching Yahoo I discovered this page in the results and I didn’t think it fit

  4. account mengatakan:

    Is it okay to insert part of this in my webpage if perhaps I post a reference point to this webpage?

  5. If you dont mind, where do you host your webpage? I am searching for a great host and your website seams to be quick and up most the time

  6. visit my website mengatakan:

    I believe that one of your ads initiated my web browser to resize, you might well need to set that on your blacklist.

  7. plr wordpress themes mengatakan:

    Yahoo results

    While searching Yahoo I discovered this page in the results and I didn’t think it fit

  8. Hello mates, good piece of writing and nice arguments commented at this
    place, I am genuinely enjoying by these.

  9. Why Do Men Pull Away mengatakan:

    Dreary Day

    It was a dreary day here yesterday, so I just took to piddeling around online and realized

  10. Looking around

    I like to surf around the internet, often I will just go to Digg and read and check stuff out

  11. Wikia

    Wika linked to this website

  12. Just Browsing

    While I was browsing yesterday I saw a excellent post about

  13. Digg

    While checking out DIGG yesterday I found this

  14. TinyCC mengatakan:

    You have nice blog, it just hard to find (at least my search) You should try one of this plugins: http://cd.vg/9448ed and/or http://cd.vg/7b02a6 I use those in all my wp blogs and I am happy with those. Both will get you better rankings in google with minimal amount of work.

  15. six pack shortcut mengatakan:

    Looking around

    I like to surf in various places on the web, regularly I will go to Stumble Upon and follow thru

  16. big cock mengatakan:

    Yahoo results

    While searching Yahoo I found this page in the results and I didn’t think it fit

  17. Lewis Lafleche mengatakan:

    Wow, amazing blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your website is excellent, let alone the content!. Thanks For Your article about Proses yang Berulang Pada Pascal | Rumah Radhen .

  18. Michaela Malsch mengatakan:

    Thanks Getty! We won’t wait around to have began!

  19. outlook mengatakan:

    Looking around

    I like to look around the online world, often I will just go to Digg and read and check stuff out

  20. epx body opportunity mengatakan:

    Its hard to find good help

    I am constantnly proclaiming that its hard to procure good help, but here is

  21. free bukkake mengatakan:

    Tumblr article

    I saw someone talking about this on Tumblr and it linked to

  22. Loyce Rothmiller mengatakan:

    Wow, wonderful blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is excellent, as well as the content!. Thanks For Your article about Proses yang Berulang Pada Pascal | Rumah Radhen .

  23. Facebook Money Cube mengatakan:

    Yahoo results

    While searching Yahoo I found this page in the results and I didn’t think it fit

  24. Bitly mengatakan:

    You have nice blog, it just hard to find (at least my search) You should try one of this plugins: http://bit.ly/17x2SrU and/or http://bit.ly/14AbDBH I use those in all my wp blogs and I am happy with those. Both will get you better rankings in google with minimal amount of work.

  25. abac bangna mengatakan:

    best ever

    Excellent function you might have finished, this website is basically interesting with excellent information and facts. Time is God’s means of retaining anything from occurring at the same time.

  26. melaleuca scam mengatakan:

    Its hard to find good help

    I am regularly saying that its difficult to procure good help, but here is

  27. free microsoft codes mengatakan:

    free microsoft codes

    […]always a significant fan of linking to bloggers that I enjoy but really don’t get a lot of link love from[…]

  28. Great Blog Post

    Awesome blog. Really thanks a ton! Cool.

  29. Floyd Maraldo mengatakan:

    Wow, awesome blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your site is wonderful, as well as the content!. Thanks For Your article about Proses yang Berulang Pada Pascal | Rumah Radhen .

  30. baju bayi mengatakan:

    Wow, wonderful blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is fantastic, as well as the content!. Thanks For Your article about Proses yang Berulang Pada Pascal | Rumah Radhen .

  31. baju bayi mengatakan:

    Wow, incredible blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your website is fantastic, as well as the content!. Thanks For Your article about Proses yang Berulang Pada Pascal | Rumah Radhen .

  32. Coy Abdalla mengatakan:

    Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your site is magnificent, let alone the content!. Thanks For Your article about Proses yang Berulang Pada Pascal | Rumah Radhen .

  33. Quentin Suchan mengatakan:

    Wow, superb blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your site is great, let alone the content!. Thanks For Your article about Proses yang Berulang Pada Pascal | Rumah Radhen .

  34. testo xl mengatakan:

    Woah! I’m really digging the template/theme of this site.
    It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance”
    between superb usability and visual appeal. I must say that you’ve done a
    amazing job with this. In addition, the blog loads
    very fast for me on Internet explorer. Superb Blog!

  35. blog motoryzacyjny mengatakan:

    I’m not that much of a online reader to be honest but your sites really nice,
    keep it up! I’ll go ahead and bookmark your site to come back down
    the road. Many thanks

  36. Today, I went to the beach front with my kids. I found a sea shell and gave it to
    my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed
    the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is completely off
    topic but I had to tell someone!

  37. mobile games mengatakan:

    I really love your site.. Pleasant colors & theme. Did you develop this website yourself?

    Please reply back as I’m attempting to create my own website
    and would like to learn where you got this from or just what the theme is named.

    Kudos!

  38. Thanks for the auspicious writeup. It in truth was a entertainment account it.

    Look advanced to more brought agreeable from you!
    By the way, how could we be in contact?

  39. Herbert mengatakan:

    Hi my family member! I wish to say that this article is amazing, nice written and include approximately
    all significant infos. I would like to see extra posts like this .

  40. This piece of writing will assist the internet viewers for building
    up new weblog or even a blog from start to end.

  41. Hello! I know this is somewhat off topic but I was wondering
    if you knew where I could locate a captcha plugin for my comment form?

    I’m using the same blog platform as yours and I’m
    having problems finding one? Thanks a lot!

  42. Clarence mengatakan:

    I believe that is one of the so much vital info
    for me. And i am happy reading your article. But wanna observation on few common issues, The website style is perfect, the articles is in reality
    excellent : D. Excellent process, cheers

  43. I have read so many posts about the blogger lovers but this
    piece of writing is actually a fastidious article, keep it up.

  44. Hi would you mind letting me know which webhost you’re utilizing?
    I’ve loaded your blog in 3 different internet browsers and
    I must say this blog loads a lot faster then most. Can you recommend a good
    internet hosting provider at a honest price?
    Cheers, I appreciate it!

Comment navigation

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s