use local temp variable to check in while condition