09_Structure
การตัดสินใจและการวนซ้ำ: if/else, match, try, for, while
การตัดสินใจและการวนซ้ำ: if/else, match, try, for, while
The structures that decide how a program branches, loops, or handles errors โครงสร้างที่กำหนดว่าโปรแกรมจะตัดสินใจ วนซ้ำ หรือจัดการข้อผิดพลาดอย่างไร
After learning boolean values and comparisons, the next step is using conditions and loops to control the order in which code runs. The table below summarises the main structures in Python — click a link to open each sub-lesson.
หลังเรียนรู้ค่าบูลีนและการเปรียบเทียบแล้ว ขั้นถัดไปคือใช้เงื่อนไขและลูปเพื่อควบคุมลำดับการทำงานของโค้ด ตารางด้านล่างสรุปโครงสร้างหลักใน Python — คลิกลิงก์เพื่อเข้าบทเรียนย่อยแต่ละหัวข้อ
| Structure | What it doesการใช้งาน | Lessonหน้าบทเรียน |
|---|---|---|
if / elif / else |
Choose a code path based on a boolean condition เลือกทางเดินโค้ดตามเงื่อนไขบูลีน | If Else |
match / case |
Match a value against several cases (instead of long if/elif) เทียบค่าหลายแบบ (แทน if/elif ยาวๆ) | Match Case |
try / except / finally |
Catch and handle errors safely จับและจัดการข้อผิดพลาดอย่างปลอดภัย | Try Except Finally |
for loop |
Repeat over a sequence or a range
วนซ้ำตามลำดับสมาชิก หรือ range
|
For Loop |
while loop |
Repeat while a condition stays true วนซ้ำตราบที่เงื่อนไขยังเป็นจริง | While Loop |