Lesson 8 of 23

while மற்றும் do-whilewhile and do-while

9 min 25 XP

எத்தனை முறை என்று தெரியாதபோது while. n % 10 கடைசி இலக்கம், n / 10 கடைசி இலக்கத்தை நீக்கும். இந்த இரண்டு tricks மூலம் reverse, palindrome number, Armstrong number போன்ற கேள்விகளைத் தீர்க்கலாம்.

Use while when you don't know how many times to loop. n % 10 is the last digit and n / 10 removes it. These two tricks solve reverse, palindrome-number and Armstrong-number questions.

Example: edit me and press Run

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

Condition ஒருபோதும் false ஆகாவிட்டால் loop முடிவில்லாமல் ஓடும். இங்கே சில வினாடிகளில் தானாக நிறுத்தப்படும்.

If the condition never becomes false the loop runs forever. Here it is stopped automatically after a few seconds.

Challenge

+25 XP

ஒரு எண்ணைப் படித்து, அது palindrome எண் (தலைகீழாக்கினாலும் அதே எண்) ஆனால் "Palindrome", இல்லையெனில் "Not palindrome" என்று print செய்யுங்கள். Input: 1221 → Output: Palindrome

Read a number. Print "Palindrome" if it reads the same reversed, otherwise "Not palindrome". Input: 1221 → Output: Palindrome

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