zhou@brazil.psych.purdue.edu (Albert Zhou) (01/04/91)
Here is the problem: Suppose there is such a structure in the main part of the program: repeat statemetn 1 statement 2 . . . statement n until whatever Now I need to write a subroutine to point the program to statement n. It seems there is no way to do it in turbo pascal, since goto statement can not go out of a subroutine. Any clue?
defaria@hpclapd.HP.COM (Andy DeFaria) (01/08/91)
>/ hpclapd:comp.lang.pascal / zhou@brazil.psych.purdue.edu (Albert Zhou) / 12:15 am Jan 4, 1991 / >Here is the problem: > Suppose there is such a structure in the main part of the program: > > repeat > statemetn 1 > statement 2 > . > . > . > statement n > until whatever > > Now I need to write a subroutine to point the program to statement n. >It seems there is no way to do it in turbo pascal, since goto statement >can not go out of a subroutine. Seems pretty simple to me: Function WhereToGo : Integer; Begin If <somecondition> then WhereToGo := 1 else If <othercondition> then WhereToGo := 2 else If <yetanothercondition> then WhereToGo := 3 else WhereToGo := MaxInt; End; { In main code.... } Repeat Case WhereToGo of 1: statement1; 2: statement2; 3: statement3; n: statementn; else WriteLn ('Do not know where to go!'); End; Until whatever; { or maybe... } Repeat JumpIndicator := WhereToGo; Case JumpIndicator of 1: statement1; 2: statement2; 3: statement3; n: statementn; End; Until JumpIndicator = MaxInt;
einstein@cs.mcgill.ca (Michael CHOWET) (01/10/91)
In article <11647@j.cc.purdue.edu> you write: >Here is the problem: > Suppose there is such a structure in the main part of the program: > > repeat > statemetn 1 > statement 2 > . > . > . > statement n > until whatever > > Now I need to write a subroutine to point the program to statement n. >It seems there is no way to do it in turbo pascal, since goto statement >can not go out of a subroutine. > Any clue? Well, not to criticize or anything, but if you're trying to do what I think you're trying to do, don't. If all you want is to stay inside your repeat, fine. If you want to enter your repeat from some line above it, IN THE SAME MODULE and such that it doesn't exit any loops before they naturally terminate, fine. If you want, however, to jump across modules or exit loops prematurely, then you've missed the whole point of Pascal, and structured programming. If indeed this *IS* what you want to do, then either restructure your program to avoid this odd state of affairs, or take up Basic. ============================================================================== Today's message was brought to you by the letter 'S', the number 6, and =====> Einstein@cs.mcgill.ca <==== =====> Mike CHOWET | McGill CSUS VP External <===== Post back soon, now y'hear... ==============================================================================