Selection: CASE · การเลือก: CASE
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
CASE OF picks one branch
- A
CASEruns the branch whose value matches the variable. - Branches are tested in order. The first match runs, and the rest are skipped.
OTHERWISEis the branch for every other value. It comes last.
ไทย
CASE OF เลือกหนึ่งสาขา
- A
CASEรันสาขา whose value ตรงกับตัวแปร - Branches ถูกทดสอบตามลำดับ Branch แรกที่ตรงจะรัน, และ其余被跳过
OTHERWISEเป็นสาขาสำหรับทุกค่าอื่นๆ It comes last
English
ไทย
DECLARE Move : CHAR
Move ← 'W'
CASE OF Move
'W' : OUTPUT "west"
'E' : OUTPUT "east"
OTHERWISE : OUTPUT "other"
ENDCASE
English
Watch out
- A character value uses single quotes:
'W'. - Each branch is one statement here. A longer branch is easier to read as an
IF.
ไทย
ระวัง
- ค่า character ใช้เครื่องหมายอัญประกาศเดี่ยว:
'W' - แต่ละ branch เป็น statement在这里 One longer branch is easier to read as an
IF
English
Common mistakes
- Close the block with
ENDCASE. - Put a colon after the value, and after
OTHERWISE.
ไทย
ข้อผิดพลาดที่พบบ่อย
- ปิด block ด้วย
ENDCASE - วาง colon หลังค่า, และหลัง
OTHERWISE
English
Now you try
- Read a character and choose a word with
CASE OF.
ไทย
ลองดูเลย
- อ่าน character และเลือกคำด้วย
CASE OF
Read a CHAR Move. Output west for W, east for E, and other for anything else. · อ่าน CHAR Move. เอาต์พุต west สำหรับ W, east สำหรับ E, และ other สำหรับทุกอย่างอื่น
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่