Video narration
When n % i == 0 is true, n has a factor besides 1 and itself. Set isPrime to 0. Then break stops the loop. There is no reason to keep dividing after you already know the number is non-prime. Finally, print the result after the loop: if (isPrime == 1) { printf("%d is prime", n); } else { printf("%d is not prime", n); } Now dry run it with 17. The status starts at 1. Since 17 is greater than 1, the loop begins. For i equal to 2, 17 % 2 is not 0. For i equal to 3, it is not 0. For i equal to 4, the loop condition fails because 4 times 4 is greater than 17. No divisor was found, so 17 is prime. Try 18 next. At i equal to 2, 18 % 2 is 0. The status becomes 0, break stops the loop, and the program prints that 18 is not prime. So the answer is simple: no random guesses. If division finds a divisor, the number is non-prime; if none appears, it is prime.