This is a typical example of the kind of code I see online.
11 lines, and none of the open braces line up with closing braces.
I would do it like this...
9 lines, exact same indenting, and every brace lines up.
Okay, I'm cheating on the last 3 braces, the order is wrong, but since they are the same character, I don't see a problem.
Code:
if (n == 0 || n == 1) {
isPrime = 0;
}
else {
for(i = 2; i <= n/2; ++i) {
if(n % i == 0) {
isPrime = 0;
break;
}
}
}
I would do it like this...
Code:
if (n == 0 || n == 1)
{ isPrime = 0;
}
else
{ for(i = 2; i <= n/2; ++i)
{ if(n % i == 0)
{ isPrime = 0;
break;
} } }
Okay, I'm cheating on the last 3 braces, the order is wrong, but since they are the same character, I don't see a problem.