Learn more

Reference


This appendix defines the structure of the Karel programming language on a single page.

Base Karel commnds:

move();
turnLeft();
putBeeper();
pickBeeper();

Karel program structures:

/* Comments can be included in any part
 * of a program. They start with a slash-star
 * and end with a star-slash.
 */
public class name extends SuperKarel {

   public void run() {
      code to execute
   }

   declarations of private methods
}

Names of the conditions:
frontIsClear()
beepersPresent()
beepersInBag()
leftIsClear()
rightIsClear()
facingNorth()
facingSouth()
facingEast()
facingWest()
frontIsBlocked() noBeepersPresent()
noBeepersInBag()
leftIsBlocked()
rightIsBlocked()
notFacingNorth()
notFacingSouth()
notFacingEast()
notFacingWest()
Conditions:

if(condition){
code run if condition passes
}

if(condition){
code block for "yes"
} else {
code block for "no"
}

Loops:

for(int i = 0; i < count; i++){
code to repeat
}

while(condition){
code to repeat
}

Method Declaration:

private voidname() {
code in the body of the method.
}

SuperKarel additional commands:

turnRight();
turnAround();
random(p);
paintCorner(color);