The main difficulty is making sure that Kara does not endlessly walk up through an exit to the next row and then back down again. He must remember whether he is looking for an exit to his right or to his left. He must ignore exits on the other side. The following extract of the main programs shows how two boolean variables can be used to search fo the next exit:

boolean ignoriereLochLinks = false;
boolean ignoriereLochRechts= true;

while (!kara.onLeaf()) {
  while ((ignoriereLochLinks || kara.treeLeft()) &&
         (ignoriereLochRechts || kara.treeRight())) {
    if (!kara.treeFront()) {
      kara.move();
    }
    else {
      ignoriereLochLinks = !ignoriereLochLinks;
      ignoriereLochRechts= !ignoriereLochRechts;
      kara.turnLeft();
      kara.turnLeft();
    }
  }
  // ....
}