This is ok:
for(int i = 1; i <= floor(sqrt(n)); i++) {
//code
}
This is good:
for(int i = 1; i * i <= n; i++) {
//code
}
This is better:
int limit = floor(sqrt(n));
for(int i = 1; i <= limit; i++) {
//code
}
@pbalduino Not sure if I agree. I mean, it's rather easy for the compiler to figure out which local variables change and which don't. I think const
should only be used to ensure const-correctness in interactions. For local variables, the only interaction I see is passing it by reference to another method.
This is a little better