Lesson 9 of 23

break, continue மற்றும் Prime எண்கள்break, continue and Prime Numbers

9 min 25 XP

break loop-ஐ உடனே நிறுத்தும். continue அந்தச் சுற்றைத் தவிர்க்கும். Prime சோதனையில் ஒரு வகுத்தி கிடைத்தவுடன் break செய்யலாம்; √n வரை சோதித்தால் போதும்.

break stops a loop immediately; continue skips the rest of the current round. When testing for a prime, break as soon as you find a divisor, and you only need to check up to √n.

Example: edit me and press Run

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

Challenge

+25 XP

a மற்றும் b படித்து, a முதல் b வரை (இரண்டும் சேர்த்து) உள்ள prime எண்களின் எண்ணிக்கையை print செய்யுங்கள். Input: 10 30 → Output: 6

Read a and b and print how many primes there are from a to b (both included). Input: 10 30 → Output: 6

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