PythonPython · Chapterبەش 7 · Lectureوانە 7.3
Controlling Loops: break and continueکۆنترۆڵکردنی خولەکان: break و continue
Leave a loop early with break, skip a round with continue, and see exactly where control jumps. Solve Lab 1's even-number tasks, meet pass and the loop else, and avoid the continue trap in while loops.
بە break زوو لە دەربچۆ، بە continue جێبهێڵە و ڕێک ببینە کۆنترۆڵ بۆ کوێ باز دەدات. ئەرکەکانی ژمارە جووتەکانی تاقیگەی 1 چارەسەر بکە، pass و elseی بناسە و خۆت لە تەڵەی continue لە بپارێزە.
What you will learnچی فێر دەبیت
- Use
breakto leave a loop andcontinueto skip one round, inforandwhileloops. - Predict the output of loops that contain
breakandcontinue. - Solve the Lab 1 even-number tasks and decide whether the end value is included.
- Explain
passand the loopelse, and avoidcontinuebefore the update in awhileloop.
breakبۆ دەرچوون لە وcontinueبۆ جێهێشتنی یەک بەکار بهێنیت، لە و .- ئەو پێشبینی بکەیت کە
breakوcontinueیان تێدایە. - ئەرکەکانی ژمارە جووتەکانی تاقیگەی 1 چارەسەر بکەیت و بڕیار بدەیت ئایا نرخی کۆتایی تێدایە یان نا.
passوelseی ڕوون بکەیتەوە و خۆت لەcontinueپێش نوێکردنەوە لە بپارێزیت.
Changing the normal flow of a loopگۆڕینی ڕەوتی جێبەجێکردنی ئاسایی خول
Normally a while loop stops only when its condition becomes False, and a for loop only when the sequence runs out. Two loop control statements change that from inside the body: break leaves the loop at once, and continue skips the rest of the current round and goes on with the next one. Both work in for and in while loops.
بە ئاسایی تەنها کاتێک دەوەستێت کە False بێت و تەنها کاتێک کە تەواو دەبێت. دوو کۆنترۆڵکردنی ئەمە لە ناو دەگۆڕن: break دەستبەجێ لە دەردەچێت و continue باقیی ئێستا جێدەهێڵێت و بە دواتر بەردەوام دەبێت. هەردووکیان لە و کار دەکەن.
A shopkeeper checks a tray of eggs one by one. A cracked egg is put aside and the checking goes on with the next egg — that is continue. If the shopkeeper finds that the whole tray is from the wrong order, the checking stops completely and the next job starts — that is break.
دووکاندارێک شانەیەک هێلکە یەک یەک دەپشکنێت. هێلکەیەکی شکاو لادەنرێت و پشکنین بە هێلکەی دواتر بەردەوام دەبێت — ئەمە continueـە. ئەگەر دووکاندارەکە بزانێت هەموو شانەکە هی داواکارییەکی هەڵەیە، پشکنین بە تەواوی دەوەستێت و کاری دواتر دەست پێدەکات — ئەمە breakـە.
Where the analogy stops workingسنووری ئەم نموونەیە
A shopkeeper can go back to an egg later. A loop never goes back: a skipped round is gone, and after break the loop does not restart.
دووکاندار دەتوانێت دواتر بگەڕێتەوە بۆ هێلکەیەک. هەرگیز ناگەڕێتەوە: جێهێڵراو ڕۆیشتووە و دوای break دەست پێ ناکاتەوە.
In Kurdish: the while loop, and how break and continue change it.
بە کوردی: و چۆن break و continue ڕەفتاری دەگۆڕن.
Kurdish (Sorani), whole video (9:36): part 17 of MR. Ant's Python course (while loop, break, continue).
ڤیدیۆیەکی کوردی (سۆرانی)، هەموو ڤیدیۆکە (9:36): بەشی 17 لە کۆرسی MR. Ant (، break و continue).
break: leave the loop nowbreak: ئێستا لە خول دەربچۆ
break stops a loop (or a switch) at once, and the program continues with the code after it. In Python it leaves only the innermost loop; PHP's break 2; can leave two nested loops.
break (یان switchـێک) دەستبەجێ دەوەستێنێت و بە کۆدی دوای ئەو بەردەوام دەبێت. لە Pythonـدا تەنها ناوەکیترین خول جێدەهێڵێت؛ break 2;ـی PHP دەتوانێت دوو خولی ناوەکی جێبهێڵێت.
When a break statement runs inside a loop body, the loop stops immediately and control moves to the first statement after the loop. Any rounds that were still to come are dropped. You can use it in a for or a while loop.
کاتێک لە ناو جێبەجێ دەبێت، دەستبەجێ دەوەستێت و کۆنترۆڵ دەچێتە سەر یەکەم دوای . هەموو تر کە هێشتا مابوو فڕێ دەدرێت. دەتوانیت لە یان بەکاری بهێنیت.
for a in range(1, 9):
if a == 3:
break
print(a)
print("After the loop")1 2 After the loop
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-3
When
ais 3,breakends the loop beforeprint(a)runs.کاتێک
a3 بێت،breakپێش جێبەجێبوونیprint(a)کۆتایی پێ دەهێنێت.- Lineدێڕی 5
Control jumps here: the first statement after the loop.
کۆنترۆڵ باز دەدات بۆ ئێرە: یەکەم دوای .
break: leave the loop nowbreak: ئێستا لە خول دەربچۆ
Using break to stop a searchبەکارهێنانی break بۆ وەستاندنی گەڕان
break is perfect for searching: look at the items one by one and stop at the first one you want. There is no need to check the rest. It is also the way out of a while True: loop, as in the input loops of The while loop.
break بۆ گەڕان زۆر گونجاوە: دانەکان یەک یەک سەیر بکە و لە یەکەمیان کە دەتەوێت بوەستە. پێویست ناکات باقییەکەی بپشکنیت. هەروەها ڕێگەی دەرچوونە لە while True:، وەک لە خولی while.
for n in range(50, 100):
if n % 7 == 0:
print("First multiple of 7 from 50:", n)
breakFirst multiple of 7 from 50: 56
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
n % 7 == 0means 7 dividesnwith no remainder.n % 7 == 0واتە 7nبەبێ دابەش دەکات.
while Trueuntil_stop.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسەwhile True:
word = input("Type a word (or stop): ")
if word == "stop":
break
print(word.upper())
print("Bye!")Type a word (or stop): hello HELLO Type a word (or stop): kurdistan KURDISTAN Type a word (or stop): stop Bye!
continue: skip to the next roundcontinue: باز بدە بۆ خولانەوەی دواتر
continue skips the rest of the current iteration and jumps to the next one. Unlike break, the loop keeps going.
continue پاشماوەی خولانەوەی ئێستا تێدەپەڕێنێت و دەچێتە سەر خولانەوەی دواتر. جیاواز لە break، بەردەوام دەبێت.
When control reaches a continue statement, the statements after it in the body are skipped for this round. The loop then moves to the next item of the sequence (or, in a while loop, back to the condition) and runs the body for it. It works in both for and while loops.
کاتێک کۆنترۆڵ دەگاتە ، هەموو کە لە دوای ئەوەوە لە بۆ ئەم جێدەهێڵرێت. پاشان دەچێتە سەر دانەی دواتری (یان لە دەگەڕێتەوە بۆ ) و بۆ ئەو جێبەجێ دەکات. لە هەردوو و کار دەکات.
for a in range(1, 9):
if a == 3:
continue
print(a)
print("After the loop")1 2 4 5 6 7 8 After the loop
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-3
When
ais 3,continueskipsprint(a)for this round only.کاتێک
a3 بێت،continueتەنها بۆ ئەمprint(a)جێدەهێڵێت.- Lineدێڕی 4
For every other value the print runs as normal.
بۆ هەموو نرخێکی تر
printبە ئاسایی جێبەجێ دەبێت.
continue: skip to the next roundcontinue: باز بدە بۆ خولانەوەی دواتر
break and continue side by sidebreak و continue لە تەنیشت یەک
The two slide programs differ in one word. The picture shows where control jumps in each: break jumps out, below the loop; continue jumps back up to the next round.
دوو سلایدەکە تەنها لە یەک وشەدا جیاوازن. وێنەکە پیشان دەدات کۆنترۆڵ لە هەر یەکێکیاندا بۆ کوێ باز دەدات: break باز دەدات بۆ دەرەوە، خوار ؛ continue باز دەدات بۆ سەرەوە، بۆ دواتر.
| Statement | Effect on this roundکاریگەری لەسەر ئەم | Effect on the loopکاریگەری لەسەر | Output of the slide program سلایدەکە |
|---|---|---|---|
break | Ends itکۆتایی پێ دەهێنێت | Ends the whole loopهەموو کۆتایی پێ دەهێنێت | 1 2 |
continue | Ends itکۆتایی پێ دەهێنێت | Goes on with the next itemبە دانەی دواتر بەردەوام دەبێت | 1 2 4 5 6 7 8 |
continue: skip to the next roundcontinue: باز بدە بۆ خولانەوەی دواتر
Watch them runسەیری جێبەجێبوونیان بکە
The animation runs both slide programs side by side, one value of a at a time. Watch what happens at a = 3.
ئەنیمەیشنەکە هەردوو سلایدەکە لە تەنیشت یەک جێبەجێ دەکات، هەر جارێک یەک نرخی a. سەیر بکە لە a = 3دا چی ڕوودەدات.


Lab task 2-1: even numbers from 0 to 40ئەرکی تاقیگە 2-1: ژمارە جووتەکان لە 0 تا 40
Write a program that prints only the even numbers between 0 and 40.
بنووسە کە تەنها ژمارە جووتەکانی نێوان 0 و 40 چاپ بکات.
Hintئاماژە
A step of 2 in range() gives only even numbers. Or test n % 2 and use continue.
هەنگاوی 2 لە range()ـدا تەنها ژمارەی جووت دەدات. یان n % 2 بپشکنە و continue بەکار بهێنە.
Show answerوەڵامەکە پیشان بدە
for n in range(0, 41, 2):
print(n, end=" ")
print()0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
The course owner's solution walks through every number and uses continue to skip the odd ones (a % 2 == 1 means "odd"):
چارەسەری خاوەنی کۆرسەکە بە هەموو ژمارەیەکدا دەڕوات و continue بەکار دەهێنێت بۆ جێهێشتنی ژمارە تاکەکان (a % 2 == 1 واتە «تاک»):
#Task 2-1
for a in range(40):
if a % 2 == 1:
continue
print(a, end=" . ")0 . 2 . 4 . 6 . 8 . 10 . 12 . 14 . 16 . 18 . 20 . 22 . 24 . 26 . 28 . 30 . 32 . 34 . 36 . 38 .
Lab task 2-2: skip 4 and 16ئەرکی تاقیگە 2-2: 4 و 16 جێبهێڵە
Repeat the previous task, but let the program ignore both 4 and 16.
ئەرکی پێشوو دووبارە بکەرەوە، بەڵام با 4 و 16 هەردووکیان پشتگوێ بخات.
Show answerوەڵامەکە پیشان بدە
for n in range(0, 41, 2):
if n == 4 or n == 16:
continue
print(n, end=" ")
print()0 2 6 8 10 12 14 18 20 22 24 26 28 30 32 34 36 38 40
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-3
Two numbers are skipped with one
continue.دوو ژمارە بە یەک
continueجێدەهێڵرێن.
The owner's solution adds the two tests to the odd test:
چارەسەری خاوەنی کۆرسەکە دوو پشکنینەکە دەخاتە سەر پشکنینی تاک:
#Task 2-2
for a in range(40):
if a % 2 == 1 or a == 4 or a == 16:
continue
print(a, end=" . ")0 . 2 . 6 . 8 . 10 . 12 . 14 . 18 . 20 . 22 . 24 . 26 . 28 . 30 . 32 . 34 . 36 . 38 .
In the owner's file the two tasks stand one after the other with no print() between them. Because both loops print with end=" . ", the second output continues on the same line as the first:
لە فایلەکەی خاوەنی کۆرسەکەدا دوو ئەرکەکە لە دوای یەکدان و هیچ print()ـێک لە نێوانیاندا نییە. چونکە هەردوو بە end=" . " چاپ دەکەن، دووەم لە هەمان دێڕی یەکەمدا بەردەوام دەبێت:
#Task 2-1
for a in range(40):
if a % 2 == 1:
continue
print(a, end=" . ")
#Task 2-2
for a in range(40):
if a % 2 == 1 or a == 4 or a == 16:
continue
print(a, end=" . ")0 . 2 . 4 . 6 . 8 . 10 . 12 . 14 . 16 . 18 . 20 . 22 . 24 . 26 . 28 . 30 . 32 . 34 . 36 . 38 . 0 . 2 . 6 . 8 . 10 . 12 . 14 . 18 . 20 . 22 . 24 . 26 . 28 . 30 . 32 . 34 . 36 . 38 .
One long line: add print() after each loop to end its line.
یەک دێڕی درێژ: دوای هەر print() زیاد بکە بۆ کۆتاییهێنان بە دێڕەکەی.
A shorter test for "is it one of these values?" uses in with a tuple of the values (see in in Working with strings):
پشکنینێکی کورتتر بۆ «ئایا یەکێکە لەم نرخانە؟» in لەگەڵ لە نرخەکان بەکار دەهێنێت (بڕوانە in لە کارکردن لەگەڵ زنجیرەنووسەکان):
for n in range(0, 41, 2):
if n in (4, 16):
continue
print(n, end=" ")
print()0 2 6 8 10 12 14 18 20 22 24 26 28 30 32 34 36 38 40
pass: a statement that does nothingpass: ڕستەیەک کە هیچ ناکات
Python needs at least one statement in every block. pass is a statement that does nothing: use it as a placeholder for a body you will write later. Do not confuse it with continue: after pass the rest of the body still runs; after continue it does not.
لە هەموو لانیکەم یەک پێویستە. pass کە هیچ ناکات: وەک جێگرەوەیەک بۆ جەستەیەک بەکاری بهێنە کە دواتر دەینووسیت. تێکەڵی مەکە لەگەڵ continue: دوای pass باقیی هەر جێبەجێ دەبێت؛ دوای continue نا.
pass بەرامبەر continuepass_vs_continue.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسەfor n in range(1, 6):
if n == 3:
pass # nothing happens: the loop goes on to print(n)
print(n, end=" ")
print()
for n in range(1, 6):
if n == 3:
continue # skip the rest of this round
print(n, end=" ")
print()1 2 3 4 5 1 2 4 5
for n in range(3):
pass # TODO: write the loop body later
print("The program still runs")The program still runs
for n in range(3):
print("Hello") File "empty_body.py", line 2
print("Hello")
^^^^^
IndentationError: expected an indented block after 'for' statement on line 1Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
Not indented, so the
forhas no body at all.بەرەوناو نەچووە، بۆیە
forهیچ جەستەیەکی نییە.
Extra: else on a loopزیادە: else لەسەر خول
A for or while loop may have an else block. It runs only if the loop finished normally, without break. This fits searches perfectly: if the loop never found what it wanted (no break), the else says so.
یان دەکرێت elseـی هەبێت. تەنها کاتێک جێبەجێ دەبێت کە بە ئاسایی تەواو بووبێت، بەبێ break. ئەمە بۆ گەڕان زۆر گونجاوە: ئەگەر هەرگیز ئەوەی نەدۆزیبێتەوە کە دەیویست (هیچ breakـێک نەبووبێت)، else ئەوە دەڵێت.
names = ["Aram", "Shilan", "Karwan"]
wanted = "Dilan"
for name in names:
if name == wanted:
print("Found", wanted)
break
else:
print(wanted, "is not in the list")Dilan is not in the list
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 7
elseis lined up withfor, not withif: it belongs to the loop.elseلە ئاستیforـدایە، نەکif: سەر بە .
n = int(input("A whole number above 1: "))
for d in range(2, n):
if n % d == 0:
print(n, "is not prime:", d, "divides it")
break
else:
print(n, "is prime")A whole number above 1: 91 91 is not prime: 7 divides it
n = int(input("A whole number above 1: "))
for d in range(2, n):
if n % d == 0:
print(n, "is not prime:", d, "divides it")
break
else:
print(n, "is prime")A whole number above 1: 13 13 is prime
This check tries every divisor from 2 to n - 1. Comparing algorithms shows three faster methods that give the same answer.
ئەم پشکنینە هەموو دابەشکەرێک لە 2ـەوە تا n - 1 تاقی دەکاتەوە. بەراوردکردنی ئەلگۆریزمەکان سێ ڕێگای خێراتر پیشان دەدات کە هەمان وەڵام دەدەن.
break stops a loop early, and a for loop's else block runs only when the loop ends without break; then how nested loops run.
break زوو دەوەستێنێت و تەنها کاتێک جێبەجێ دەبێت کە بەبێ break کۆتایی بێت؛ پاشان چۆن کار دەکەن.
Plays 3:42-6:30, "Loop control and else clause": break, and an else block that runs only if the loop was not broken.
لە 3:42 تا 6:30 پەخش دەبێت، بەشی Loop control and else clause: break و کە تەنها کاتێک جێبەجێ دەبێت بە break نەوەستابێت.
Common mistakesهەڵە باوەکان
The worst trap: continue in a while loop before the counter is updated. The update is skipped, the counter never changes, and the loop never ends:
خراپترین تەڵە: continue لە پێش نوێکردنەوەی . نوێکردنەوەکە جێدەهێڵرێت، هەرگیز ناگۆڕێت و هەرگیز کۆتایی نایەت:
n = 0
while n < 5:
if n == 2:
continue
print(n)
n += 10 1 … (nothing more is printed, but the program never stops: press Ctrl+C)
Real run: it printed 0 and 1 and then hung.
جێبەجێکردنی ڕاستەقینە: 0 و 1ی چاپ کرد و پاشان گیری خوارد.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3-4
When
nis 2,continuejumps back to the condition beforen += 1runs:nstays 2 for ever.کاتێک
n2 بێت،continueپێش جێبەجێبوونیn += 1باز دەداتەوە بۆ :nبۆ هەمیشە 2 دەمێنێتەوە.
n = 0
while n < 5:
n += 1
if n == 2:
continue
print(n)1 3 4 5
| Mistakeهەڵە | What happensچی ڕوودەدات | Fixچارەسەر |
|---|---|---|
continue before the update in a while loopcontinue پێش نوێکردنەوە لە | Infinite loop | Update the counter firstسەرەتا نوێ بکەرەوە |
break outside any loopbreak لە دەرەوەی هەموو | SyntaxError: 'break' outside loopSyntaxError: 'break' outside loop | Use it only inside a loop bodyتەنها لە ناو بەکاری بهێنە |
Expecting break to leave all nested loopsچاوەڕوانی ئەوەی break لە هەموو دەربچێت | Only the innermost loop endsتەنها ناوەکیترین کۆتایی دێت | See Nested loopsبڕوانە خولە ناوەکییەکان |
Using pass to skip a roundبەکارهێنانی pass بۆ جێهێشتنی | Nothing is skippedهیچ شتێک جێناهێڵرێت | Use continuecontinue بەکار بهێنە |
if a==3:break | Works, but hard to readکار دەکات، بەڵام خوێندنەوەی قورسە | Two lines, spaces around ==دوو دێڕ، لە دەوری == |
break بەبێ خولbreak_outside.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسەage = 15
if age < 18:
break File "break_outside.py", line 3
break
^^^^^
SyntaxError: 'break' outside loopExercisesڕاهێنانەکان
Print the numbers 1 to 20 on one line, but skip every multiple of 3.
ژمارەکانی 1 تا 20 لە یەک دێڕدا چاپ بکە، بەڵام هەموو چەندجارێکی 3 جێبهێڵە.
Show answerوەڵامەکە پیشان بدە
for n in range(1, 21):
if n % 3 == 0:
continue
print(n, end=" ")
print()1 2 4 5 7 8 10 11 13 14 16 17 19 20
Read numbers until the user types 0. Ignore negative numbers (say so), and print the total of the others. Use while True, break and continue.
ژمارە بخوێنەرەوە تا 0 دەنووسێت. پشتگوێ بخە (ئەمەش بڵێ) و کۆی ئەوانی تر چاپ بکە. while True، break و continue بەکار بهێنە.
Show answerوەڵامەکە پیشان بدە
total = 0
while True:
number = int(input("Number (0 to stop): "))
if number == 0:
break
if number < 0:
print("Negative numbers are ignored.")
continue
total += number
print("Total:", total)Number (0 to stop): 5 Number (0 to stop): -3 Negative numbers are ignored. Number (0 to stop): 10 Number (0 to stop): 0 Total: 15
What does this program print? Explain each step.
ئەم چی چاپ دەکات؟ هەموو هەنگاوێک ڕوون بکەرەوە.
for n in range(10):
if n % 2 == 0:
continue
if n > 6:
break
print(n)Show answerوەڵامەکە پیشان بدە
for n in range(10):
if n % 2 == 0:
continue
if n > 6:
break
print(n)1 3 5
Even numbers are skipped by continue. The odd numbers 1, 3 and 5 are printed. At 7 the test n > 6 is True, so break ends the loop and 9 is never reached.
ژمارە جووتەکان بە continue جێدەهێڵرێن. ژمارە تاکەکانی 1، 3 و 5 چاپ دەکرێن. لە 7دا پشکنینی n > 6 Trueـە، بۆیە break کۆتایی پێ دەهێنێت و هەرگیز ناگاتە 9.
Ask for a word and print its first vowel. If it has none, print No vowel in … — use a loop else.
داوای وشەیەک بکە و یەکەم پیتی بزوێنی چاپ بکە. ئەگەر هیچی نەبوو، No vowel in … چاپ بکە — elseی بەکار بهێنە.
Show answerوەڵامەکە پیشان بدە
word = input("A word: ")
for letter in word:
if letter.lower() in "aeiou":
print("First vowel:", letter)
break
else:
print("No vowel in", word)A word: Hawler First vowel: a
word = input("A word: ")
for letter in word:
if letter.lower() in "aeiou":
print("First vowel:", letter)
break
else:
print("No vowel in", word)A word: Sky No vowel in Sky
break لە خولێک لە ناو خولێکی ترداHere a for loop runs inside another for loop: for every x, the inner loop tries y = 1 to 5. Predict the output. Does break stop both loops?
لێرەدا لە ناو تردا جێبەجێ دەبێت: بۆ هەر xـێک، y لە 1 تا 5 تاقی دەکاتەوە. پێشبینی بکە. ئایا break هەردوو دەوەستێنێت؟
for x in range(1, 4):
for y in range(1, 6):
if x * y > 6:
break
print(x * y, end=" ")
print("| row", x, "done")
print("All rows done")Hintئاماژە
break leaves only the loop it is written in — here the inner for y loop.
break تەنها لەو دەردەچێت کە تێیدا نووسراوە — لێرەدا ناوەوە، for y.
Show answerوەڵامەکە پیشان بدە
for x in range(1, 4):
for y in range(1, 6):
if x * y > 6:
break
print(x * y, end=" ")
print("| row", x, "done")
print("All rows done")1 2 3 4 5 | row 1 done 2 4 6 | row 2 done 3 6 | row 3 done All rows done
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3-4
Ends only the inner loop; the line
print("| row", x, "done")still runs.تەنها کۆتایی پێ دەهێنێت؛ دێڕی
print("| row", x, "done")هەر جێبەجێ دەبێت.
- Row 1: is never above 6, so the inner loop runs all five rounds.
- Row 2: at
y = 4, , sobreakends the inner loop after 2 4 6. - Row 3: at
y = 3, : only 3 and 6 are printed. - The outer loop is never stopped: all three rows finish and
All rows doneis printed.
- ڕیزی 1: هەرگیز لە 6 زیاتر نییە، بۆیە هەر پێنج جارەکە جێبەجێ دەبێت.
- ڕیزی 2: کاتێک
y = 4، ، بۆیەbreakدوای 2 4 6 کۆتایی پێ دەهێنێت. - ڕیزی 3: کاتێک
y = 3، : تەنها 3 و 6 چاپ دەکرێن. - هەرگیز ناوەستێت: هەر سێ ڕیزەکە تەواو دەبن و
All rows doneچاپ دەکرێت.
Summaryپوختە
breakends the whole loop at once; control goes to the first statement after the loop.continueskips the rest of this round and goes on with the next one.- Both work in
forandwhileloops;breakleaves only the innermost loop. - Lab 1:
range(0, 41, 2)gives the even numbers to 40;continuecan skip chosen values; end each output line withprint(). passdoes nothing (a placeholder); a loop'selseruns only when nobreakhappened.- In a
whileloop, update the counter before anycontinue.
breakدەستبەجێ هەموو کۆتایی پێ دەهێنێت؛ کۆنترۆڵ دەچێتە سەر یەکەم دوای .continueباقیی ئەم جێدەهێڵێت و بە دواتر بەردەوام دەبێت.- هەردووکیان لە
forوwhileـدا کار دەکەن؛breakتەنها لە ناوەکیترین دەردەچێت. - تاقیگەی 1:
range(0, 41, 2)ژمارە جووتەکان تا 40 دەدات؛continueدەتوانێت نرخە هەڵبژێردراوەکان جێبهێڵێت؛ هەر دێڕێکی بەprint()کۆتایی پێ بهێنە. passهیچ ناکات (جێگرەوەیە)؛elseی تەنها کاتێک جێبەجێ دەبێت کە هیچbreakـێک ڕووی نەدابێت.- لە پێش هەر
continueـێک نوێ بکەرەوە.
What is the output of the slide's break program (range(1, 9), break at 3)?دەرخستەی بەرنامەی breakـی سلایدەکە (range(1, 9)، break لە 3دا) چییە؟
1 and 2.
1 و 2.
And of the continue program?هی بەرنامەکە continue چی؟
1 2 4 5 6 7 8 — only 3 is missing.
1 2 4 5 6 7 8 — تەنها 3 نییە.
What is the difference between pass and continue?جیاوازیی نێوان pass و continue چییە؟
pass does nothing and the body goes on; continue skips the rest of the body for this round.
pass هیچ ناکات و بەردەوام دەبێت؛ continue باقیی بۆ ئەم جێدەهێڵێت.
Why did the owner's Task 2-1 output stop at 38?بۆچی دەرخستەی ئەرکی 2-1ی خاوەنی کۆرسەکە لە 38دا وەستا؟
range(40) stops at 39, and 39 is odd; use range(41) to include 40.
range(40) لە 39دا دەوەستێت و 39 تاکە؛ بۆ ئەوەی 40 تێدا بێت range(41) بەکار بهێنە.
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
break leaves a loop at once, continue skips to the next round, and pass is a statement that does nothing.
break دەستبەجێ لە دەردەچێت، continue بۆ داهاتوو باز دەدات و pass کە هیچ ناکات.
Whole video (4:40). Chapters: 0:20 break, 1:30 continue, 2:57 pass.
هەموو ڤیدیۆکە (4:40). بەشەکان: 0:20 break، 1:30 continue، 2:57 pass.
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Nested Loops and Patternsخولە ناوەکییەکان و کێشانی شێوە
Related lecturesوانە پەیوەندیدارەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.