Could not add conditional into the while statement