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 not kara.onLeaf if not kara.treeLeft kara.turnLeft kara.move else if not kara.treeFront kara.move else if not kara.treeRight kara.turnRight kara.move end end end end kara.removeLeaf