Fix variable scoping of do-while