cprogramnewbie
Your loop is no loop. As GertFaller stated, when the program goes into the for-loop, it immediately returns.
Much easier would be to extend your condition. The example below shows how such is done, in case you didn't know such is possible.
Further you should use return only at the end of your function. In general this makes a program much easier to read and to understand. I always introduce a return value which value is set by the code in the function and returned at the end.
Code:
is_prime = TRUE
for (i = 2; i < prime && is_prime == TRUE; i++)
{
if (prime % i == 0)
is_prime = FALSE;
}
return (is_prime == FALSE) : 'n' ? 'p';
Gugge
Also to you, don't use so much returns in your function. You also have logic error in your code. In your while loop, which is not really a while loop, an if-else construction is used which results in an immediate return. So the last return in the function will never be reached. To avoid problems like this, it is better to keep a return value.
Further, assume
prime = 9
i = 2
then
9 % 2 == 1
So your function says: that it is a prime?