Indentation

Indentation is used to help programmers with nesting. A lot of code will be nested within each other. This website has refered to this as code blocks (see the java mini site for more details). We indent each new code block to help the programmer to see where a block starts and when a block ends.

Look at the two bits of code. Which one is more readable? See why we use indentation!

for(int a=0; a<numbers.length; a++){
for(int b=0; b<numbers.length - (a+1); b++){
if(numbers[b] > numbers[b + 1] ){
int temp = numbers[b];
numbers[b] = numbers[b+1];
numbers[b+1] = temp;
}
}
}

or

for(int a=0; a<numbers.length; a++){
      for(int b=0; b<numbers.length - (a+1); b++){
             if(numbers[b] > numbers[b + 1] ){
                   int temp = numbers[b];
                    numbers[b] = numbers[b+1];
                    numbers[b+1] = temp;
              }
      }
}