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
3 Réponses
+ 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"
+ 1
Nice 👍
0
Wong Hei Ming Oh thank u