you have an eternal loop
maxheight >0 ?
Check what logic you are really after something tells me you have misunderstood something in the assignment