0

Why this code doesn't work properly but when i add 《break》it works?

This is a code to check if the numbers in a list are prime or not... but without break it doesn't work properly why??? https://code.sololearn.com/csV9UxwPFEPY/?ref=app

23rd Nov 2023, 8:33 PM
Amateur
3 odpowiedzi
+ 3
Guess you mean it has to put "break" in line 11 to make it work. Currently your code is working in this way. 1. At line 5, i = 26 and we know it is not a prime number. 2. At line 7, j = 2 3. At line 9 and 10, 26 % 2 == 0, and assign "not prime" to variable result. Without a "break", it goes back to line 7 again and j becomes 3. 4. It iterate until i = 85 and j = 84, 85 % 84 is not equal to 0, and "prime" is assigned into variable result. 5. Finally it prints the result "prime"
24th Nov 2023, 2:11 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
Nice 👍
25th Nov 2023, 1:37 PM
Munni Devi
Munni Devi - avatar
0
Wong Hei Ming Oh thank u
24th Nov 2023, 5:19 AM
Amateur