Hello,
Recently I use a goto control in the following block.
Notice thatCode:float fInput = -1; do { cin >> fInput; if (fInput == 0) goto EXIT_; if (fInput > 0) Client1.setLoanAmt(fInput); else cout << " Invalid input, try again: $"; } while (fInput < 0); unsigned uYears = -1; do { cin >> uYears; if (uYears == 0) goto EXIT_; if (uYears > 0) Client1.setYears(uYears); else cout << " Invalid input, try again: "; } while (uYears < 0);
unsigned uYears = -1;
is after the first do while(){} loops containing
goto EXIT_;
Well, VC7 never complains anything but VC6 says initialization 'uYears' is skipped by the goto statement. My initial intension was to put all relevant code together as close as where it will be used. I can see why VC6 errors out that the variable 'uYears' is skipped. But Why do I bother to care about its initialization if other code ahead of it failed and lead to exit. ie., I really want to skip initialize it.
My solution to this in VC6 is to bring the 'unsigned uYears = -1;' before ALL goto statement. But why VC7 took it? Did VC7 fix the VC6 difficiency or break? That is also interesting to me.
Ant takers?
Tom.