RE: goto considered essential
- Posted by Jason Gade <jaygade at yahoo.com> Jan 22, 2006
- 442 views
Lynn Kilroy wrote: > > > Jason Gade wrote: > > > > > > posted by: Jason Gade <jaygade at yahoo.com> > > > > Lynn Kilroy wrote: > > > > > > Wasn't there an exit thingabobbers I saw mentioned somewhere? I thought > > > > > > it would be neat to use, because it doesn't exist in QBasic, and I had > > > to setup escape sequences that would abort my loops by resetting > > > variables and stuff. Really messy and unclear. Exit looked like a > > > great alternative. > > > > > > Love & Friendship & Blessed Be! > > > Lynn Erika Kilroy > > > > Yes, there is an exit statement. It will leave the current while or for > > loop that you are in. It only exits one level, though. > > > > And unfortunately there is no corresponding continue statement, that > > would jump back to the top of the loop. > > > > -- > > "The author regrets that he is unable to reconcile himself to the > > thoughtful point of view you have expressed. However, it must be kept > > in mind that being raised in different cultures and different places can > > result in such differences of viewpoint between individuals. > > The author is from planet Earth." [author unknown] > > > > j. > > Would there be an instance where exiting one would want you to exit > another? I mean, without the other really expecting it? I mean, if you > set it up to Exit one, you could, just prior to exiting the one loop, > setup to exit the one it's nested in if necessary. > > Love & Friendship & Blessed Be! > Lynn Erika Kilroy > > Good question. Generally there can be conditions in a deeply nested loop where you need to exit the whole thing. Of course that can introduce problems of its own, such as do you use a number or a variable or a label to determine how many loops you exit? Otherwise outer loops have to check flags to determine whether they need to exit or not. Sometimes you just have to refactor your routine to figure a better way of doing it and not get caught up trying to get too elegant. -- "The author regrets that he is unable to reconcile himself to the thoughtful point of view you have expressed. However, it must be kept in mind that being raised in different cultures and different places can result in such differences of viewpoint between individuals. The author is from planet Earth." [author unknown] j.