Need a little help with a while loop

Instead of jumping into writing this custom code, I might suggest some tutorials first, check the Learn link at the top of this page. I would expect it to go to your first case, you explicitly set the value just prior. Debug.Log it! Tips for new Unity users