השלכות משולבות
הוצג
9:10
אלגוריתמים ותכנות
דמיינו ספר טלפונים עם מיליון שמות, ועליכם למצוא אחד. תבדקו אותם אחד אחד, ותיתכן שתעמדו שם כל היום. יש דרך למצוא אותו בתוך כ-…
קריינות באנגלית · כתוביות באנגלית ובסינית 中文 שאפשר להחליף ביניהן
בשיעור הזה
| English | משמעות |
|---|---|
| nested conditional/ˈnestɪd kənˈdɪʃənl/ | הוראת תנאי מקוננת |
| three or more/θriː ɔː mɔː/ | שלושה או יותר |
| outcomes/ˈaʊtkʌmz/ | תוצאות |
| else-if/els ɪf/ | אלא אם כן |
| execution path/ˌeksɪˈkjuːʃn pæθ/ | מסלול ביצוע |
| readability/ˌriːdəˈbɪlɪti/ | קריאות |
When two paths aren't enough
- Sometimes one decision is not enough.
- A nested conditional 嵌套条件语句 places one conditional inside another.
- This lets a program select among three or more 三个或更多 outcomes 结果, not just two.
- Think grades A, B, C, F — four outcomes from one score.
השלכה משולבת מאפשרת לתוכנית:
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
השלכה מוסיפה יותר ערוצים מאשר IF/ELSE יחיד.
תנאי מקונן בוחר מתוך שלושה או יותר ______ אפשריות.
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
כל ענף מוביל לתוצאה שונה.
The else-if structure
- A clean way to write this is an else-if 否则如果 structure, testing conditions in sequence:
- IF the first is true, do the first thing;
- ELSE IF the second is true, do the second thing;
- ELSE do the last thing.

A nested conditional: the inner decision runs only in one branch of the outer one
שרשרת else-if לדרגות
גרור את הנקודות והסתכל איזה ערוץ רץ. שרשרת else-if בודקת מלמעלה למטה ונוטלת את התנאי הראשון שהוא אמת.
שרשרת else-if מפסיקה לבדוק:
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
היא נוטלת את הערוץ האמיתי הראשון ומדלגת על שארם.
סדר בה תוכנית בודקת את תנאי הדרגות.
רמת קושי 3/5 · 200 מטבעות + בונוס קטן בהשלמה הראשונה היום
הוא בודק מלמעלה למטה ועוצר בראש תנאי שהתקיים.
Trace the path
- The program checks conditions from top to bottom.
- It stops at the first one that is true.
- To understand nested conditionals, trace the execution path 执行路径 for given inputs.
- Follow each true-or-false result to see which branch wins.
עם שרשרת הדרגות (≥90 A, ≥80 B, ≥70 C, אחרת F), נקודות 85 תיתנו:
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
85 ≥ 90 הוא שגוי; 85 ≥ 80 הוא אמת → "B", ובדיקה עוצרת.
פישוט של תנאים מקוננים בעומק משפר את קריאות הקוד ומפחית שגיאות.
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
ענפים מעטים וברורים יותר קלים להבין ולממש נכון.
Keep it readable
- Deeply nested logic can become hard to read.
- Simplify overly complex nesting to improve readability 可读性 and reduce errors.
Score to grade. IF score ≥ 90 → "A"; ELSE IF ≥ 80 → "B"; ELSE IF ≥ 70 → "C"; ELSE → "F". For score 85: 85 ≥ 90 is false, so move on; 85 ≥ 80 is true → grade "B", and testing stops. Order matters — we already know it is below 90.
A nested conditional places one conditional inside another. An else-if chain can choose among three or more outcomes by testing top to bottom and stopping at the first true condition. Trace the execution path to find which branch runs (score 85 → "B"), and keep nesting shallow for readability.
מה השתבש? רק צוות האתר רואה זאת.