Post Reply 
GO TO? JUMP? [Solved]
11-25-2015, 03:29 PM (This post was last modified: 11-25-2015 03:34 PM by Han.)
Post: #3
RE: GO TO? JUMP?
(11-25-2015 03:08 PM)jrozsas Wrote:  Hello.
My question is how to create a return to a specific point of a program after sub.
Example:

1: Export goto()
2: BEGIN
3: nonononono
4: nonoononon
5: nonononono
6: Text();
7: END;

8: //sub Text
9: Text()
10: BEGIN
11: RECT;
12: TEXTOUT_P("Choose the function.",1,1,4);
13: WAIT(2);
14: END;

How to return to the line "3" after running sub Text() ?
Examples?

In your sample code, a simple while loop would suffice:

1: Export goto()
2: BEGIN

while 1 do
3: nonononono
4: nonoononon
5: nonononono
6: Text();
end

7: END;

You can create the equivalent of goto using:
Code:
EXPORT MYPROG()
BEGIN
  LOCAL label:=#FFFFFh;
  WHILE 1 DO

    IF (label AND #1h) THEN
    // here is code for first "block"
    END;

    IF (label AND #2h) THEN
      label:=MYSUB()
      IF label THEN CONTINUE; ELSE BREAK; END;
    END;

    IF (label AND #3h) THEN
    // code block 3
    END;

  END; // end while

END;

Each if statement can be considered like a label for a code block. If you want to run through the entire set of blocks, set label:=#FFFFFh (here we are assuming only up to 2^20 labels). If you only want to jump to a specific code block, set label equal to that particular block (e.g. label:=#3h would only execute the third block).

This particular scheme, however, would have severe runtime issues if you have many "labeled" blocks of code. I am not particularly fond of GOTO; they are great for assembly-level programs (in fact necessary) but in higher level languages I find that I seldom, if ever, use them.

EDIT: Much of the code in the example can be made simpler through the use of subroutines.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
GO TO? JUMP? [Solved] - jrozsas - 11-25-2015, 03:08 PM
RE: GO TO? JUMP? - Didier Lachieze - 11-25-2015, 03:22 PM
RE: GO TO? JUMP? - Han - 11-25-2015 03:29 PM
RE: GO TO? JUMP? - jrozsas - 11-25-2015, 04:47 PM
RE: GO TO? JUMP? - primer - 11-25-2015, 05:03 PM
RE: GO TO? JUMP? - jrozsas - 11-25-2015, 05:17 PM
RE: GO TO? JUMP? - jrozsas - 11-25-2015, 05:27 PM
RE: GO TO? JUMP? - jrozsas - 11-25-2015, 05:29 PM
RE: GO TO? JUMP? - ji3m - 11-26-2015, 12:05 AM



User(s) browsing this thread: 1 Guest(s)