Loops

Put spaces in between mathematical operators as if they are alone.

Put spaces after semicolons.

BAD:

for(int i=0;i<100;i++){
  
}

GOOD:

for(int i = 0; i < 100; ++i) {
  
}

In a for loop, instead of i++, try ++i. The latter has one less operation.

Prefer while loops to do...while. The former is easier to understand at a glance.

Last updated

Was this helpful?