The loop that never ends · הלולאה ש jamais נגמרת
The loop that never ends
Run this first and watch what happens. The line that makes count smaller is there — but it is outside the loop, so it never runs.
In Python the indentation is the structure: lines indented under while belong to the loop and repeat, a line back at the left margin comes after the loop and runs once at the end. Here the loop never reaches its last line, so its question stays true for ever. The page will notice and stop it for you, but your program should stop itself.
הלולאה לעולם לא מסתיימת
הפעל זאת קודם ועיין מה קורה. השורה ההופכת את count לקטן קיימת — אך היא מחוץ ללולאה, ולכן לעולם לא תופעל.
ב-Python המרווחים הם המבנה: שורות מוזזות תחת while שייכות ללולאה ונשנות; שורה החוזרת לשולי השמאל מגיעה לאחר הלולאה ומופעלת פעם אחת בסוף. כאן הלולאה לעולם לא מגיעה לשורה האחרונה שלה, ולכן השאלה שלה נשארת נכונה לנצח. העמוד יבחין בכך ויעצור אותך, אך התוכנית שלך צריכה לעצור את עצמה.
Run this first and watch what happens. The line that makes count smaller is there — but it is outside the loop, so it never runs. Move it inside so the program prints 5, 4, 3, 2, 1 and stops. · הפעל זאת קודם וצפה מה יקרה. השורה שהופכת את count לקטן יותר קיימת — אך היא בחוץ ללולאה, ולכן לעולם לא רצה. הזז אותה לתוך הלולאה כך שהתוכנית תדפיס 5, 4, 3, 2, 1 ותיעצר.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.