Struktur IF-THEN dan IF-THEN-ELSE (Kontrol Program)

Struktur IF-THEN dan IF-THEN-ELSE (Kontrol Program) harianjaDi dalam pemrograman kita mengenal istilah struktur penyeleksian Kondisi (Conditional Statemaent) dan struktur perulangan (looping). Kedua struktur ini sangat penting dalam mengontrol suatu program yang kita buat. Tanpa menggunakan kontrol ini program yang kita buat tidak berdaya apa-apa. Penyeleksian kondisi atau pernyataan kondisi (conditional statement) merupakan suatu pernyataan yang menganalisa suatu keadaan dan mengambil keputusan  berdasarkan pada hasil analisa itu. Hasil dari penyeleksian jika bernilai benar maka akan dikerjakan instruksi tertentu. Jika salah maka akan dikerjakan instruksi yang lain.
CONTOH:
Terdapat pernyataan bahwa jika cuaca hujan maka” saya tinggal di rumah”, sedang tidak hujan “saya main bola”.

Bentuk strukturnya:

If (cuaca = “hujan” ) then
            tindakan =”tinggal di rumah”
Else
            tindakan =”main bola”
End if

Struktur IF-THEN
Disebut juga dengan branch sturucture

Merupakan struktur percabangan dimana suatu ekspresi akan dikerjakan jika kondisinya terpenuhi. Tetapi jika kondisi tidak terpenuhi maka ekspresi di dalam struktur if tidak akan dijalankan dan blok if akan dilompati serta program akan melakukan tindakan berikutnya.
BENTUK STRUKTURNYA:
            IF (KONDISI) THEN
                …….EKSPRESI……
            END IF
Kondisi:
Perbandigan antara satu variabel/konstanta dengan variabel/konstanta lain   dengan menggunakan tanda <, >, =, <>, >=, <=.
Ekspresi:
Rangkaian kode program (blok program) yang akan dijalankan jika kondisinya bernilai benar (memenuhi syarat).

Contoh:
Buat suatu program yang akan menyeleksi suatu inputan nilai akhir mahasiswa. Inputan nilai dilakukan lewat inputbox melalui prosedur form_click. Lakukan seleksi pada nilai tersebut yaitu jika nilainya lebih besar atau sama dengan 55  cetak keterangan”lulus”. Tetapi jika tidak  terpenuhi program akan berakhir. Asumsikan inputan nilai antara 0 sampai 100.
Private sub form_click()
      dim nilai_akhir as integer
      nilai_akhir = inputbox(“ketik nilai akhir”)
      if (nilai_akhir) >= 55 then
                  print “nilai_akhir : “ & nilai_akhir
                  print “keterangan : lulus “
      end if
End sub


Struktur IF-THEN-ELSE
Disebut juga dengan selection structure

Merupakan struktur percabangan dimana suatu ekspresi akan dikerjakan jika kondisinya terpenuhi. Jika tidak terpenuhi maka ekspresi yang lain akan dikerjakan.

Struktur if then else sbb:
            if (kondisi) then
                        ….ekspresi 1….
            else
                        ….ekspresi 2…..
            end if

Ekspresi 2: rangkaian kode program(blok program) yang akan dijalankan jika kondisinya bernilai salah (tidak memenuhi syarat)
Contoh:
Buat suatu program yang akan menyeleksi suatu inputan nilai akhir mahasiswa. Inputan nilai dilakukan lewat inputbox melalui prosedur form_click. Lakukan seleksi pada nilai tersebut yaitu jika nilainya lebih besar atau sama dengan 55  cetak keterangan”lulus”. Tetapi jika tidak  terpenuhi cetak keterangan “gagal”. Asumsikan inputan nilai antara 0 sampai 100.
private sub form_click()
       dim nilai_akhir as integer
       nilai_akhir = inputbox(“ketik nilai akhir”)
       if (nilai_akhir) >= 55 then
                   print “nilai_akhir : “ & nilai_akhir
                   print “keterangan : lulus “
       else
                   print “keterangan : gagal “
       end if
end sub
Pada kondisi tertentu di dalam struktur if then else bisa ditempatkan struktur if then atau if then else yang lain. Bentuk semacam ini biasa disebut if tersarang atau nested if.
Bentuk penulisan dari struktur ini adalah sebagai berikut:

If (kondisi 1) then
            if (kondisi 2)  then
                        …ekspresi 1…
            else
                        …ekspresi 2
            end if
Else
            ekspresi 3
End if
Atau
If (kondisi 1) then
            if (kondisi 2)  then
                        …ekspresi 1…
            else
                        …ekspresi 2
            end if
Else
            if (kondisi 3) then
                        …ekspresi 3…
            else
                        …ekspresi 4…
End if
End if

Penulisan di atas dapat juga digabungkan antara else dan if untuk kondisi yang ketiga dan dengan membuang  satu end if, seperti berikut:
If (kondisi 1) then
            if (kondisi 2)  then
                        …ekspresi 1…
            else
                        …ekspresi 2
            end if
Else if (kondisi 3) then
                        …ekspresi 3…
            else
                        …ekspresi 4…
End if

Keterangan:
Ø  Kondisi 1:Berisi perbandingan antara satu variabel/konstanta dg variabel lain dengan menggunakan tanda >,<,<>,=,>=,<=
Ø  Kondisi 2 : akan dikerjakan jika nilai kondisi 1 benar(terpenuhi)
Ø  Kondisi 3: akan dikerjakan jika nilai kondisi 1 adalah salah(tdk terpenuhi)
Ø  Ekspresi 1 : rangkaian kode program(blok program) yang akan
                     dijalankan jika kondisi 1  dan 2 bernilai benar(memenuhi syarat)
Ø  Ekspresi 2 : rangkaian program yang akan dijalankan jika kondisi 1 benar
          dan kondisi 2 bernilai salah
Ø  Ekspresi 3 : rangkaian program yang akan dijalankan jika kondisi 1  salah
          tetapi kondisi 3 bernilai benar
Ø  Ekspresi 4 : rangkaian program yang akan dijalankan jika kondisi 1 salah

          dan kondisi 3 juga salah

Contoh:
Buat sebuah program menyeleksi jenis kelamin dan status perkawinan seseorang dimana keduanya diinputkan lewat inputbox. Jika seseorang jenis kelaminnya “pria”, lakukan seleksi apakah “sudah menikah”. Jika keduanya terpenuhi, tampilkan “ayah” sedangkan jikat tidak terpenuhi tampilkan ”jejaka”. Tetapi jika jenis kelaminya “wanita/bukan pria”, lakukan pengecekan apakah statusnya “sudah menikah”. Jika keduanya terpenuhi, tampilkan “ibu” sedangkan tidak terpenuhi tampilkan “perawan”. Ketik listing programnya pada prosedur form_click seperti berikut:
Dim jenis as string
Dim status as string
Jenis = inputbox (“jenis kelamin”)
Status = inputbox (“sudah menikah”)
Print “jenis kelamin : “ & jenis
Print “sudah menikah : “ & status
Print “keterangan : “;
If jenis  = “pria” then
            if status = “sudah” then
                        print “ayah”
            else
                        print “jejaka”
            end if
Else
            if status =”sudah” then
                        print “ibu”
            else
                        print “perawan”
            end if
End if


Contoh Pemakaian Dalam Program (Program Login)
Private sub command1_click()
If tuser.text <> "" and tpas.text <> "" then
    set rslogin = new adodb.recordset
        rslogin.locktype = adlockoptimistic
        rslogin.cursortype = adopendynamic
        rslogin.open "select * from login where user_name = '" & tuser.text & "' and password = '" & tpas.text & "'", conn, , , adcmdtext
        if not rslogin.eof then
        msgbox ("login anda berhasil")
        form1.show
        login.visible = false
        else
            msgbox "user name dan password salah silahkan ulangi kembali", vbcritical
            exit sub
        end if
End if
End sub

Subscribe to receive free email updates:

43 Responses to "Struktur IF-THEN dan IF-THEN-ELSE (Kontrol Program)"

  1. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
    tally training in chennai

    hadoop training in chennai

    sap training in chennai

    oracle training in chennai

    angular js training in chennai




    ReplyDelete
  2. You need to participate in a challenge for probably the best webpage on the web. I will enthusiastically suggest this site!
    Paint

    ReplyDelete
  3. In the wake of going over a modest bunch of the blog articles on your site, I really appreciate your procedure of composing a blog. I bookmarked it to my bookmark site page list and will return sooner rather than later. Kindly look at my site also and let me understand your opinion.
    gadget media

    ReplyDelete
  4. I read your article it is very interesting and every concept is very clear, thank you so much for sharing. AWS Certification Course in Chennai

    ReplyDelete
  5. Replies

    1. Hello
      Please i just took up macaw breeding as a hobby after my mom passed away because they were her favorite birds. Despite the fact that they are very intelligent, am finding it very difficult getting them to mate.
      For any information CLICK HERE http://supremeparrotfarm.company.com/ we shall get back to you. contact-about-us. THANKS

      Delete
  6. Hello
    Please i just took up LABRADOR PUPPIES breeding as a hobby after my mom passed away because they were her favorite PUPPIES. Despite the fact that they are very intelligent, am finding it very difficult getting them to mate.
    For any information CLICK HERE LABRADOR PUPPIES FOR SALE. THANKS

    ReplyDelete
  7. Hello
    Please i just took up LABRADOR PUPPIES breeding as a hobby after my mom passed away because they were her favorite PUPPIES. Despite the fact that they are very intelligent, am finding it very difficult getting them to mate.
    For any information CLICK HERE http://championlabradorhomes.company.com/. THANKS

    ReplyDelete
  8. Ucuz, kaliteli ve organik sosyal medya hizmetleri satın almak için Ravje Medyayı tercih edebilir ve sosyal medya hesaplarını hızla büyütebilirsin. Ravje Medya ile sosyal medya hesaplarını organik ve gerçek kişiler ile geliştirebilir, kişisel ya da ticari hesapların için Ravje Medyayı tercih edebilirsin. Ravje Medya internet sitesine giriş yapmak için hemen tıkla: https://www.ravje.com

    İnstagram takipçi satın almak için Ravje Medya hizmetlerini tercih edebilir, güvenilir ve gerçek takipçilere Ravje Medya ile ulaşabilirsin. İnstagram takipçi satın almak artık Ravje Medya ile oldukça güvenilir. Hemen instagram takipçi satın almak için Ravje Medyanın ilgili sayfasını ziyaret et: instagram takipçi satın al

    Tiktok takipçi satın al istiyorsan tercihini Ravje Medya yap! Ravje Medya uzman kadrosu ve profesyonel ekibi ile sizlere Tiktok takipçi satın alma hizmetide sunmaktadır. Tiktok takipçi satın almak için hemen tıkla: tiktok takipçi satın al

    ReplyDelete
  9. Ucuz, kaliteli ve organik sosyal medya hizmetleri satın almak için Ravje Medyayı tercih edebilir ve sosyal medya hesaplarını hızla büyütebilirsin. Ravje Medya ile sosyal medya hesaplarını organik ve gerçek kişiler ile geliştirebilir, kişisel ya da ticari hesapların için Ravje Medyayı tercih edebilirsin. Ravje Medya internet sitesine giriş yapmak için hemen tıkla: www.ravje.com

    İnstagram takipçi satın almak için Ravje Medya hizmetlerini tercih edebilir, güvenilir ve gerçek takipçilere Ravje Medya ile ulaşabilirsin. İnstagram takipçi satın almak artık Ravje Medya ile oldukça güvenilir. Hemen instagram takipçi satın almak için Ravje Medyanın ilgili sayfasını ziyaret et: instagram takipçi satın al

    Tiktok takipçi satın al istiyorsan tercihini Ravje Medya yap! Ravje Medya uzman kadrosu ve profesyonel ekibi ile sizlere Tiktok takipçi satın alma hizmetide sunmaktadır. Tiktok takipçi satın almak için hemen tıkla: tiktok takipçi satın al

    İnstagram beğeni satın almak için Ravje medya instagram beğeni satın al sayfasına giriş yap, hızlı ve kaliteli instagram beğeni satın al: instagram beğeni satın al

    Youtube izlenme satın al sayfası ile hemen youtube izlenme satın al! Ravje medya kalitesi ile hemen youtube izlenme satın almak için tıklayın: youtube izlenme satın al

    Twitter takipçi satın almak istiyorsan Ravje medya twitter takipçi satın al sayfasına tıkla, Ravje medya güvencesi ile organik twitter takipçi satın al: twitter takipçi satın al

    ReplyDelete
  10. The breed became very popular in the early 1900s, and in 1913 and 1914, https://oneshoppharmacy.comthey were among the 10 most popular entries in the Westminster Kennel Club Show. During World War I, however, the breed fell on hard times in the U.S. and England because they were poodle for saleclosely associated with Germany. Dachshund owners sometimes were called traitors and their dogs stoned. After
    World War I, some U.S. breedersdachshunds for sale imported some Dachshunds from Germany and the breed started to become popular once again. The breed faced a similar fate during World War II, but not nearly so severely as during World War I.
    In the 1950s, Dachshunds became one of the most popular family dogs in the U.S. again, a status they have enjoyed ever
    since. While Dachshunds mini dachshund puppy for salerarely are used as hunting dogs in the U.S. or Great Britain, in other parts of Europe, especially France, they still are considered hunting dogs. Today the Dachshund ranks sixth among the 155 breeds and varieties recognized by the AKC.Dachshund dogs love apartment life.mini dachshund puppies for sale Because of their small size, they don’t need a backyard, but they
    do enjoy going on walks outside. Dachshunds also love a challenge, and as long as you incorporate plenty of opportunities to chase and find things, you’llminiature dachshund for sale have a happy dog.These dogs love their human parents, and really don’t want them to leave. Your dog may struggle more with separation anxiety, and when they’re missing you, they’re likely to chew. When you do leave your home without your dog, you may want to use a kennel.

    ReplyDelete
  11. Dachshunds are bred and shown in two sizes: Standard and Miniature.https://www.cutespupsforsale.com/ Standard Dachshunds of all varieties (Smooth, Wirehair, and Longhair) usually weigh between 16 and 32 pounds. Miniature Dachshunds of all varieties weigh 11 pounds and under atteacup poodle for sale maturity. Dachshunds that weigh between 11 and 16 pounds are called Tweenies. While this isn't an official classification, Tweenies are not penalized in the show ring. Some people who breed exceptionally small Dachshunds advertise them as Toy Dachshunds, but this is purely a poodles for salemarketing term, not a recognized designation.The Dachshund is described as clever, lively, and courageous to the point of rashness. He's bred for perseverance, which is another way of saying that he can be stubborn. Dachshunds have a reputation for being dachshund puppies saleentertaining and fearless, but what they want most is to cuddle with their people. For many Dachshund people, this characteristic outweighs having to deal with the breed's insistence on having his own way. The Dachshund personality can also vary with coat type. Because the wirehaired Dachshunds have terrier in their background, they can be mischievous troublemakers. Longhairs are calm and quiet, and Smooths havedachshund for sale a personality that lies somewhere in between. Some Mini Dachshunds can be nervous or shy, but this isn't correct for the breed. Avoid puppies that show these characteristics.Like every dog, Dachshunds need early socialization-exposure to many different people, dachshund puppies for sale near mesights, sounds, and experiences-when they're young. Socialization helps ensure that your Dachshund puppy grows up to be a well-rounded dog. Enrolling him in a puppy kindergarten class is a great start. Inviting visitors over regularly, and taking him to busy parks, stores that allow dogs, and on leisurely strolls to meet neighbors will also help him polish his social skills.

    ReplyDelete
  12. The dachshund was bred in Germany hundreds of years ago to hunt badgers.https://www.poodlespring.com/ "Dach" means badger and "hund" means dog. The three varieties of dachshund, smooth-,Dachshund puppies for sale wire-,and long-coated, originated at different times. The smooth was the first and arose from a mixture of a miniature French pointer and a pinscher. The breed also comes in two sizes: standard and miniature, with the standard the original size.
    The dachshund has short, strong legs that enable the dog to dig out prey and go inside burrows. Larger versions of the breed were used to chase deer or fox. Smaller dachshunds Dachshund puppy for salewere bred for hunting hares and ferrets.
    The breed is still used for hunting, primarily in Europe, but in North America this dog is usually a family pet. In fact, it is one of the most popular AKC breeds.
    Miniatures are not a separate AKC classification but compete in a class division for "11 pounds and under at 12 months of age and older." Weight of the standard size is usually between 16 and 32 pounds. There is no height standard for the dachshund but they are usually under nine indachshunds puppies for saleches in height.All three types are known for their long backs and short muscular legs, which explains the unflattering nicknames "sausage hound" or "hot dog." They also have a long muzzle, long and droopy ears, and a tail carried in line with the back.
    The dachshund's coat may be shades of red, black, chocolate, white or gray. Some have tan markings or are spotted or dappled. Dachshunds live about 12 to 15 years.toy poodle for saleespite their size, dachshunds are known for their courageous nature and will take on animals much larger than themselves. Some may be aggressive toward strangers and other dogs.
    As family dogs, dachshunds are loyal companions and good watchdogs. They are good with children if treated well. They can be slightly difficult to train.
    Some dachshund fanciers say there are personality differences among the different varieties of the breed. For instance, the long-coat dachshund is reportedly calmerteacup poodles for sale than the smooth-coat variety, and the wire-coat dachshund is more outgoing and clown-like.Dachshunds were bred as hunters so it is no surprise that many of them like to dig. Some are also barkers, and, in one survey, dachshunds ranked high for destructiveness.

    ReplyDelete
  13. Ahaa, its nice dialogue about this piece of writing at this place at this webpage,
    I have read all that, so at this time me also commenting here.
    havanese dogs for sale

    Hi, I do believe this is a great website. I stumbledupon it ;) I am going to revisit yet
    again since I book-marked it. Money and freedom is the greatest way to
    change, may you be rich and continue to help other people.
    havanese puppies for sale


    I used to be suggested this website by means of my cousin. I’m now not sure whether
    this submit is written by him as nobody else know such detailed approximately my problem.
    You’re incredible! Thanks!
    teacup havanese puppy


    Hi my family member! I want to say that this
    post is awesome, nice written and include almost all
    important infos. I’d like to peer more posts like this
    chocolate havanese puppy for sale


    Hello, constantly i used to check blog posts here early in the
    daylight, since i like to find out more and more.
    havanese puppy for sale

    ReplyDelete
  14. Thanks for sharing your thoughts. I truly appreciate your efforts and I will be waiting for your further
    write ups thanks once again
    pomeranian puppies for sales


    This information is invaluable. Where can I find out more?
    pomeranian for sale


    This is the right webpage for anyone who hopes to understand this topic.
    You realize a whole lot its almost hard to argue with you (not that I really would want to…HaHa).
    You definitely put a fresh spin on a topic that’s been discussed for a long
    time. Great stuff, just excellent!
    teacup pomeranian for sale near me


    It’s amazing to pay a quick visit this website and
    reading the views of all colleagues concerning this article,
    while I am also zealous of getting familiarity.
    pomeranians for sale near me


    I take pleasure in, result in I discovered exactly what I used to be taking a look
    for. You’ve ended my 4 day lengthy hunt! God Bless you man. Have a nice
    day. Bye
    pomeranian teacup for sale

    ReplyDelete
  15. Hey! are using WordPress for your blog platform?

    I’m new to the blog world but I’m trying to get started and create my own. Do you need any html coding
    expertise to make your own blog? Any help would be really appreciated!
    doodle puppies


    Thank you for the good writeup. It in reality was a enjoyment account it.

    Look complicated to far introduced agreeable from you!
    By the way, how could we communicate?
    aussiedoodle puppies for sale


    Good post. I certainly love this website.
    Continue the good work!
    bernedoodle puppies for sale


    Hey! I’m at work browsing your blog from my new iphone
    3gs! Just wanted to say I love reading through your blog
    and look forward to all your posts! Keep up the outstanding work!
    goldendoodle puppies for sale

    ReplyDelete
  16. Generally I don’t learn post on blogs, but I would like
    to say that this write-up very pressured me to try and do so!
    Your writing taste has been surprised me. Thanks, quite
    great article.
    ragdoll kitten for sale


    whoah this blog is excellent i love studying your articles.
    Keep up the good work! You recognize, lots of individuals are looking around for thisinfo, you could help them greatly.
    ragdoll kittens for sale


    Good post. I certainly love this website.
    Continue the good work!
    mini goldendoodle for sale

    Hey! I’m at work browsing your blog from my new iphone
    3gs! Just wanted to say I love reading through your blog
    and look forward to all your posts! Keep up the outstanding work!
    mini bernedoodle puppies for sale

    I’m new to the blog world but I’m trying to get started and create my own. Do you need any html coding
    expertise to make your own blog? Any help would be really appreciated!
    mini aussiedoodles for sale

    ReplyDelete
  17. At this time I am going away to do my breakfast, afterward having my breakfast coming over again to read further news
    ragdoll cat for sale


    Usually I don’t read post on blogs, but I wish to say that this write-up very compelled me to try and do it!
    Your writing taste has been surprised me. Thank you, very nice article.
    ragdoll cats for sale

    Hi, I do think this is a great blog. I stumbledupon it �� I may come back once again since I saved as a favorite it.
    Money and freedom is the greatest way to change, may you be rich and continue
    to guide others.
    aussiedoodle for sale

    Wonderful article! That is the kind of info that are supposed to be shared around the net.
    Shame on the seek engines for now not positioning this publish upper!
    Come on over and discuss with my website . Thank
    you =)
    bernedoodles for sale

    What’s Going down i’m new to this, I stumbled upon this I have found It positively useful and it has aided me out loads.
    I hope to give a contribution & help different users like its aided me.
    Good job.
    goldendoodle for sale

    ReplyDelete
  18. I love what you guys are usually up too. This sort of clever work and coverage! Keep up the excellent works guys I’ve you guys to my own blogroll.
    ragdoll kittens for sale near me


    Hi, of course this piece of writing is actually fastidious and I have learned lot
    of things from it concerning blogging. thanks.
    ragdoll kitten near me

    https://thegorgeousdoodles.com/
    https://www.fluffyhavanese.com/
    https://www.pomeranianpuppiesforsales.com/
    https://thegorgeousragdolls.com/

    ReplyDelete
  19. you will need support or suggestions, write me privately.
    I interested in your implementation/use case.
    the best kera4d
    Togel2win

    ReplyDelete
  20. Fantastic website. I have read all the comments and suggestions here . Know About the visa requirements for Turkey . The requirements generally differ as per the visa type and differ as per the country status.

    ReplyDelete
  21. WhatsApp Plus v19.32 Crack application that is messaging for Android system only. This application works on your phones that are different. Whatsapp Plus Crack

    ReplyDelete
  22. It is a strong and collective item which is established on and utilized by loads of people in the world. that asks for can move all Microsoft items easily utilizing a single tick for essentially life use. https://cyberspc.com/re-loader-activator-crack/

    ReplyDelete
  23. wow, nambah pengetahuan banget seputar dunia programming. Terimakasih!

    ReplyDelete
  24. Christmas Messages for use in Cards and Letters. May abundant peace and vibrant joy be yours this Christmas season; Wishing you a wonderful holiday season Christmas Wishes For Love

    ReplyDelete

  25. Remarkable! Its truly remarkable post, I have got much clear idea about from this article.https://crackwindow.com/windows-10-iso/

    ReplyDelete