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

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
Amazing experience on reading your article. It is really nice and informative.
ReplyDeletePython Training in Chennai
Python Training in T.Nagar
JAVA Training in Chennai
Big data training in chennai
Selenium Training in Chennai
Python Training in Annanagar
Thanks for sharing with us that awesome article you have amazing blog..............
ReplyDeleteBig Data Hadoop Training In Chennai | Big Data Hadoop Training In anna nagar | Big Data Hadoop Training In omr | Big Data Hadoop Training In porur | Big Data Hadoop Training In tambaram | Big Data Hadoop Training In velachery
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.
ReplyDeletetally training in chennai
hadoop training in chennai
sap training in chennai
oracle training in chennai
angular js training in chennai
You need to participate in a challenge for probably the best webpage on the web. I will enthusiastically suggest this site!
ReplyDeletePaint
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.
ReplyDeletegadget media
thank Python Training in chennai | Python Classes in Chennai you for your post
ReplyDeleteinstagram takipçi satın al \n instagram takipçi satın al \n takipçi satın al \n takipçi satın al \n instagram takipçi satın al \n takipçi satın al \n instagram takipçi satın al \n aşk kitapları \n tiktok takipçi satın al \n instagram beğeni satın al \n youtube abone satın al \n twitter takipçi satın al \n tiktok beğeni satın al \n tiktok izlenme satın al \n twitter takipçi satın al \n tiktok takipçi satın al \n youtube abone satın al \n tiktok beğeni satın al \n instagram beğeni satın al \n trend topic satın al \n trend topic satın al \n youtube abone satın al \n beğeni satın al \n tiktok izlenme satın al \n sms onay \n youtube izlenme satın al \n tiktok beğeni satın al \n sms onay \n sms onay \n perde modelleri \n instagram takipçi satın al \n takipçi satın al \n tiktok jeton hilesi \n pubg uc satın al \n sultanbet \n marsbahis \n betboo \n betboo \n betboo
ReplyDeletemarsbahis
ReplyDeletebetboo
sultanbet
marsbahis
betboo
sultanbet
DeleteHello
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
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
ReplyDeleteİ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
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
ReplyDeleteİ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
Amazing post! I really liked it
ReplyDeleteMobile Prices Bangladesh
ReplyDeleteNice & Informative Blog ! We offer welcome to yorkie puppies nearme. Check it out!...
puppies for sale near me
yorkie puppies with home training
where to buy Yorkie
Yorkie Female Puppies for sale
Yorkie puppies ready for their forever homes
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.
ReplyDeleteThanks for sharing your thoughts. I truly appreciate your efforts and I will be waiting for your further
ReplyDeletewrite 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
At this time I am going away to do my breakfast, afterward having my breakfast coming over again to read further news
ReplyDeleteragdoll 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
1- takipçi satın al
ReplyDelete2- takipçi satın al
3 - takipçi satın al
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
ReplyDeleteIt 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/
ReplyDeletewow, nambah pengetahuan banget seputar dunia programming. Terimakasih!
ReplyDeleteChristmas 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
ReplyDeleteKindly Visit my website for cracked software, Windows & Mac. Download Now Latest Versions.
ReplyDeleteMicrosoft Office 2019 Crack
The Vivo Y22s is a mid-range smartphone released in December 2020. It has a 6.51-inch IPS LCD display with a resolution of 720 x 1600 pixels. It is powered by a MediaTek Helio P35 chipset with 4 GB of RAM and 128 GB of internal storage.
ReplyDeletevivo y22s price and full specs
sms onay satın al sms tr onay
ReplyDeleteEv kadınlarına Yardım başvurusu
ReplyDeleteMobil onay satın al
ReplyDeleteEmbedded training center in Chennai
ReplyDeletebest embedded training institute in Chennai
plc training center in Chennai
plc scada vfd dcs hmi training institute in Chennai
best final year Project center in Chennai
best final year Project center in Chennai