ความหมายของ If และ Else
IF คือ คำสั่งควบคุม ใช้ตรวจสอบเงื่อนไข ถ้าหากว่าเงื่อนไขเป็นจริง ก็จะทำตามคำสั่งที่กำหนด เช่น ถ้าค่า x > 100 ให้แสดงผล คำว่า "ถูกต้อง" อะไรประมาณนี้แหละ ครับ
ELSE จะเป็นตัวที่ทำงานต่อจาก If ก็คือ ถ้า ได้ค่าอะไร ที่นอกเหนือจากที่กำหนดโดย "if" ก็ให้ข้ามการทำงานมาทำที่ else แทน
ตัวอย่าง เช่น
int num = 250;
if ( num > 250 ) {
System.out.print ( "จำนวนมาก" );
}
else {
System.out.print ( "จำนวนน้อย" );
}
อธิบาย Code นี้
เมื่อจำนวน num = 250 ถ้า num มากว่า 250 ให้แสดงคำว่า "จำนวนมาก" แต่ถ้านอกเหนือจากนั้น ให้แสดงคำว่า "จำนวนน้อย"
*นี่เป็นแค่พื้นฐานในการใช้คำสั่ง If และ Else นะครับ 'เราสามารถเอาพื้นฐานนี้ไปประยุกต์ในการเขียนโปรแกรมได้มากมายเลย ครับ
*นี่เป็นแค่พื้นฐานในการใช้คำสั่ง If และ Else นะครับ 'เราสามารถเอาพื้นฐานนี้ไปประยุกต์ในการเขียนโปรแกรมได้มากมายเลย ครับ
Hey there!
ตอบลบGreat stuff dude. After a long week of work from healthcare app development company and website development company in India your article helps to chill a lot.
Keep up the good work!
aTeam Soft Solutions is a reputed iOS, Android and Web Development Company of Dallas that helps in creating a dynamic web presence for your business. The company is specialized in providing customized solutions for all your digital requirement.
ตอบลบ