Leaf search in forrest III

While Kara is not on a leaf, he tests whether he can step ahead or turn left or turn right, and takes the appropriate action.

while (! kara.onLeaf()) {
  if (!kara.treeLeft()) {
    kara.turnLeft();
    kara.move();
  }
  else if (!kara.treeFront()) {
    kara.move();
  }
  else if (!kara.treeRight()) {
    kara.turnRight();
    kara.move();
  }
}
kara.removeLeaf();