Fixing a brain dead for loop