Iteration: WHILE and REPEAT · איטרציה: WHILE ו-REPEAT
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
WHILE tests first
- A pre-condition loop tests the condition, then maybe runs the body.
- If the condition is already
FALSE, the body never runs. - The block ends at
ENDWHILE.
עברית
WHILE בודק קודם
- לולאת תנאי מקדים בודקת את התנאי, ואז אולי מריצה את הגוף.
- אם התנאי כבר
FALSE, הגוף לעולם לא יירץ. - הבloq נגמר ב
ENDWHILE.
DECLARE N : INTEGER
N ← 3
WHILE N > 0
OUTPUT N
N ← N - 1
ENDWHILE
English
REPEAT runs, then tests
- A post-condition loop runs the body, then tests.
- The body runs at least once.
- The loop stops when the condition becomes
TRUE.
עברית
REPEAT מריצה קודם, ובועד אחרי
- לולאת תנאי מאחורי מריצה את הגוף, ואז בודקת.
- הגוף מורץ לפחות פעם אחת.
- הלולאה נעצרת כאשר התנאי הופך ל-
TRUE.
DECLARE N : INTEGER
N ← 0
REPEAT
N ← N + 1
OUTPUT N
UNTIL N = 3
English
Watch out
WHILEstops onFALSE.REPEATstops onTRUE. They are opposite tests.- Something inside a
WHILEmust change the condition, or the loop never ends.
עברית
שימו לב
WHILEנעצר ב-FALSE.REPEATנעצר ב-TRUE. הם בדיקות הפוכות.- משהו בתוך
WHILEחייב לשנות את התנאי, אחרת הלולאה לעולם לא תיגמר.
English
Common mistakes
ENDWHILEcloses aWHILE.UNTILcloses aREPEAT.- A
REPEATthat should stop at 3 must updateNbefore the test.
עברית
טעויות נפוצות
ENDWHILEסוגרWHILE.UNTILסוגרREPEAT.- לולאת
REPEATשצריכה להיעצר ב-3 צריכה עדכן אתNלפני הבדיקה.
English
Now you try
- Write one
WHILEand oneREPEAT.
עברית
כעת תנסו בעצמכם
- כתוב לולאת
WHILEולולאתREPEATאחת.
Set N to 3. While N is greater than 0, output N and then subtract 1. · מנהל את N ל3. עד שN גדול מ0, הדפס את N ולאחר מכן חסר את 1.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
Use REPEAT … UNTIL to output 1, 2 and 3. · השתמש בREPEAT … UNTIL כדי להדפיס את 1, 2 ו3.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.