Lesson 9 of 23

break, continue and Prime Numbers

9 min 25 XP

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

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.