Commit b5802a8
committed
feat: Check if a number is prime and print its factors using break and continue
🧠 Logic:
- Given a number (143), loop from 2 to number-1 to check for divisibility.
- If divisible, print it's not prime and use `break` to exit early.
- If the loop reaches the end without finding a divisor, the number is prime.
- Use a `while` loop to find and print all factors of the number.
- Skip non-factors using `continue`.
- Print the factor when found.
🎯 Focus:
Demonstrates usage of `break` to exit a loop and `continue` to skip to the next iteration.
Signed-off-by: Somesh diwan <[email protected]>1 parent 88da4e1 commit b5802a8
File tree
1 file changed
+7
-13
lines changed- Section7ConditionalStatements/Loops/src
1 file changed
+7
-13
lines changedLines changed: 7 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
5 | 3 | | |
6 | 4 | | |
7 | | - | |
8 | | - | |
| 5 | + | |
| 6 | + | |
9 | 7 | | |
10 | | - | |
11 | | - | |
| 8 | + | |
12 | 9 | | |
13 | 10 | | |
14 | 11 | | |
| |||
18 | 15 | | |
19 | 16 | | |
20 | 17 | | |
21 | | - | |
22 | | - | |
| 18 | + | |
23 | 19 | | |
24 | 20 | | |
25 | | - | |
26 | | - | |
| 21 | + | |
27 | 22 | | |
28 | 23 | | |
29 | 24 | | |
30 | 25 | | |
31 | | - | |
32 | 26 | | |
33 | 27 | | |
0 commit comments