Lesson 14 of 34

break மற்றும் continuebreak and continue

8 min 30 XP

break: loop-ஐ உடனே முழுவதுமாக நிறுத்தும். continue: இந்தச் சுற்றின் மீதியைத் தவிர்த்து, அடுத்த சுற்றுக்குச் செல்லும்.

break stops the whole loop immediately. continue skips the rest of this round and moves to the next one.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

while True என்பது “எப்போதும் தொடர்”. break வரும் வரை loop ஓடும். பயனர் “stop” என்று எழுதும் வரை வார்த்தைகளைப் பெற இது உதவும்.

while True means “keep going forever” until a break. It's handy for reading input until the user types “stop”.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Challenge

+30 XP

எண்களை ஒவ்வொன்றாக input() மூலம் பெறுங்கள். 0 வந்தால் நிறுத்துங்கள் (break). எதிர்மறை (negative) எண்களைத் தவிர்த்து (continue), நேர்மறை எண்களின் கூட்டுத்தொகையை மட்டும் கடைசியில் print செய்யுங்கள்.

Read numbers one by one with input(). Stop when you get 0 (break). Skip negative numbers (continue) and, at the end, print the sum of the positive numbers only.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.