When programmers write code, they tend to stick to an indentation style which essentially makes the program easier to read. When programs get more complex, there are often a number of lines of code which contain loops within loops amongst other things. If all code was written starting at the left edge of the page for every line, it would quickly become unreadable. Take the following example:
import stanford.karel.*;
public class BeeperPickingKarel extends Karel {
public void run() {
move();
if (noBeepersPresent()) {
pickBeeper();
}
move();
}
{
Although this selection of code is relatively simple and with a bit of effort, is fairly readable, it is still recommended that you indent your code to make the blocks and other statements stand out. Indenting and adding more line breaks in the code above would produce the following:
[Read more…]