Update variable while running if statement