Iteration: FOR · איטרציה: FOR (לולאה)
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
FOR counts
- A count-controlled loop runs once for each integer from the start to the end, inclusive.
- The counter is an
INTEGER. - It is good practice to repeat the counter's name after
NEXT.
עברית
FOR סופר
- מחזור בשליטת ספירה מריץ פעם אחת עבור כל שלם מהתחלה ועד הסוף, כולל הקצוות.
- השולחן הוא
INTEGER. - זהו הליכה טובה להכפיל את שם השולחן לאחר
NEXT.
DECLARE Total : INTEGER
Total ← 0
FOR I ← 1 TO 5
Total ← Total + I
NEXT I
OUTPUT Total
Explore · חקור
Trace the running total · עקוב אחר הסכום הנערך
A FOR loop repeats a set number of times. Step through and watch Total grow. · לולאת FOR חוזרת על מספר קבוע פעמים. צעד שלב אחר שלב וצפה כיצד Total גדל.
English
STEP changes the jump
STEPsets the gap between values. It can be negative.- If the start is already past the end in the step's direction, the body does not run.
עברית
STEP משנה את הקפיצה
STEPקובע את הפער בין ערכים. הוא יכול להיות שלילי.- אם ההתחלה כבר חורגת מהסוף בכיוון השלב, הגוף לא מריץ.
FOR I ← 5 TO 1 STEP -2
OUTPUT I
NEXT I
English
Watch out
NEXT Imust name the counter of this loop.- The body is indented.
NEXTlines up withFOR.
עברית
שימו לב
NEXT Iחייב לציין את סופר ה-לולאה הזו.- הגוף מודגש בתוךן.
NEXTמיושר עםFOR.
English
Common mistakes
1 TO 5includes both 1 and 5.- Do not change the counter yourself inside the body.
עברית
טעויות נפוצות
1 TO 5כולל גם את 1 וגם את 5.- אל תשנה את הסופר בעצמך בתוך הגוף.
English
Now you try
- Use a
FORloop to print a run of numbers.
עברית
כעת תנסו בעצמכם
- השתמש בלולאת
FORכדי להדפיס רצף של מספרים.
Use a FOR loop to output the numbers 1 to 5, one per line. · השתמש בלולאת FOR כדי להדפיס את המספרים מ-1 ועד 5, מספר אחד בכל שורה.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
Output 5, 3 and 1, using FOR with STEP -2. · הדפס 5, 3 ו1, תוך שימוש בFOR עם STEP -2.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.