Logic: AND, OR, NOT
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · หน้านี้ต้องใช้เบราว์เซอร์ล่าสุด (รองรับ SharedArrayBuffer) กรุณาอัปเดต Chrome, Edge, Firefox หรือ Safari เป็นเวอร์ชันล่าสุด
English
A club that checks your age
- A coding club takes members only from age 11 to 16. One test cannot say both ends.
ANDisTRUEonly when both tests areTRUE.- Write the variable on each side:
Age >= 11 AND Age <= 16.
ไทย
A club that checks your age
- A coding club takes members only from age 11 to 16. One test cannot say both ends.
ANDisTRUEonly when both tests areTRUE- Write the variable on each side:
Age >= 11 AND Age <= 16
DECLARE Age : INTEGER
Age ← 14
IF Age >= 11 AND Age <= 16
THEN
OUTPUT "accepted"
ELSE
OUTPUT "no"
ENDIF
English
OR: either test is enough
- A bus fare is free for a child or a senior: under 5, or 65 and over.
ORisTRUEwhen at least one test isTRUE.
ไทย
OR: either test is enough
- ค่ารถบัสฟรีสำหรับเด็ก หรือ ผู้สูงอายุ: อายุต่ำกว่า 5 ปี หรือ 65 ปีขึ้นไป
ORเป็นTRUEเมื่อมีข้อสอบTRUEอย่างน้อยหนึ่งข้อ
DECLARE Age : INTEGER
Age ← 70
IF Age < 5 OR Age >= 65
THEN
OUTPUT "free"
ELSE
OUTPUT "pay"
ENDIF
English
NOT flips a Boolean
NOTturnsTRUEintoFALSE, andFALSEintoTRUE.- A search that has not found the target yet is
NOT Found.
ไทย
NOT พลิกค่า Boolean
NOTเปลี่ยนTRUEเป็นFALSE, และFALSEเป็นTRUE- การค้นหาที่ยังไม่พบเป้าหมายคือ
NOT Found
DECLARE Found : BOOLEAN
Found ← FALSE
IF NOT Found
THEN
OUTPUT "missing"
ENDIF
English
Watch out
Mark >= 0 AND <= 100is not a test. The second half has nothing to compare.- Parentheses make a mix obvious:
NOT (Age < 11 OR Age > 16).
ไทย
ระวัง
Mark >= 0 AND <= 100ไม่ใช่การทดสอบ ส่วนหลังไม่มีอะไรให้เปรียบเทียบ- วงเล็บช่วยให้เห็นความชัดเจน:
NOT (Age < 11 OR Age > 16)
English
Common mistakes
AND,ORandNOTare keywords. Their operands areBOOLEAN, usually from a relational test.9618putsTHENon theIFline. This course keepsTHENon the next line.
ไทย
ข้อผิดพลาดที่พบบ่อย
AND,ORและNOTคือกุญแจคำ (keywords) อาร์กิวเมนต์ของพวกมันคือBOOLEANซึ่งมักมาจากเงื่อนไขเชิงสัมพันธ์9618วางTHENไว้บรรทัดที่IFCourses นี้จะเก็บTHENไว้บรรทัดถัดไป
English
Now you try
- Each task is one decision. Write both sides of
ANDand ofOR. - Press Check answer to test it.
ไทย
ลองดูเลย
- แต่ละงานคือการตัดสินใจหนึ่งครั้ง เขียนทั้งสองข้างของ
ANDและของOR - กด Check answer เพื่อทดสอบ
Read an INTEGER Age. Output accepted when it is from 11 to 16 inclusive, using AND. Otherwise output no. · อ่าน INTEGER Age. แสดง accepted เมื่ออยู่ระหว่าง 11 ถึง 16 รวมขอบเขต, ใช้ AND. มิฉะนั้นแสดง no
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
Read an INTEGER Age. Output free when Age is under 5 or at least 65, using OR. Otherwise output pay. · อ่าน INTEGER Age. เอาต์พุต free เมื่อ Age ต่ำกว่า 5 หรืออย่างน้อย 65, ใช้ OR. มิฉะนั้นเอาต์พุต pay
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
Found is a BOOLEAN set to FALSE. If NOT Found, output missing. · Found เป็น BOOLEAN set to FALSE. ถ้า NOT Found, แสดงผล missing
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่