Post Reply 
GO TO? JUMP? [Solved]
11-25-2015, 03:08 PM (This post was last modified: 09-06-2016 11:35 AM by jrozsas.)
Post: #1
GO TO? JUMP? [Solved]
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?

Leo

Visit this user's website Find all posts by this user
Quote this message in a reply
11-25-2015, 03:22 PM
Post: #2
RE: GO TO? JUMP?
(11-25-2015 03:08 PM)jrozsas Wrote:  How to return to the line "3" after running sub Text() ?
Examples?

What about:

Code:
1:  Export goto()
2:  BEGIN
2b: REPEAT
3:     nonononono
4:     nonoononon
5:     nonononono
6:     Text();
6b: UNTIL end_condition;
7:  END;
Find all posts by this user
Quote this message in a reply
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
11-25-2015, 04:47 PM
Post: #4
RE: GO TO? JUMP?
I thank the answers but do not understand. This is litle program that creates the menu, and after displaying the message in the sub(n), it should return to the line 13 (or 8?) to show the splash screen again.

1: SUB1();
2: SUB2();
3: SUB3();
4: SUB4();
5: SUB5();
6: SUB6();
7: EXPORT EC(x)
8: BEGIN
9: // CAS Custom Menu
10: // EWS 2014-04-20
11://splashscreen
12: LOCAL m,m1,mx,my;
13: WHILE MOUSE(1)≥0 DO END;
14: RECT;
15: TEXTOUT_P("How to GOTO?",1,1,4);
16:
17:
18: DRAWMENU("opt1","opt2","opt3","opt4","opt5","opt6");
19:
20: REPEAT
21: m:=MOUSE;
22: m1:=m(1);
23: UNTIL SIZE(m1)>0;
24: mx:=m1(1);
25: my:=m1(2);
26:
27:
28:
29: IF mx≥0 AND mx≤51 THEN
30: SUB1();
31: END;

32: IF mx≥53 AND mx≤104 THEN
33: SUB2();
34: END;

35: IF mx≥106 AND mx≤157 THEN
36: SUB3()
37: END;
38:
39: IF mx≥159 AND mx≤210 THEN
40: SUB4();
41: END;
42:
43: IF mx≥212 AND mx≤263 THEN
44: SUB5();
45: END;
46:
47: IF mx≥265 AND mx≤319 THEN
48: SUB6();
49: END;
50:
51: END;
52:
53: //SUB1
54: SUB1()
55: BEGIN
56: RECT;
57: TEXTOUT_P("PRESS SUB1",1,1,4);
58: WAIT(2);
59: END;
60:
61: //SUB2
62: SUB2()
63: BEGIN
64: RECT;
65: TEXTOUT_P("PRESS SUB1",1,1,4);
66: WAIT(2);
67: END;
68:
69: //SUB3
70: SUB3()
71: BEGIN
72: RECT;
73: TEXTOUT_P("PRESS SUB1",1,1,4);
74: WAIT(2);
75: END;
76:
77 //SUB4
78: SUB4()
79: BEGIN
80: RECT;
81: TEXTOUT_P("PRESS SUB1",1,1,4);
82: WAIT(2);
83: END;
84:
85: //SUB5
86: SUB5()
87: BEGIN
88: RECT;
89: TEXTOUT_P("PRESS SUB1",1,1,4);
90: WAIT(2);
91: END;
92:
93: //SUB6
94: SUB6()
95: BEGIN
96: RECT;
97: TEXTOUT_P("PRESS SUB1",1,1,4);
98: WAIT(2);
99: END;

[/font]

Leo

Visit this user's website Find all posts by this user
Quote this message in a reply
11-25-2015, 05:03 PM
Post: #5
RE: GO TO? JUMP?
something like that :
Code:

...
7: EXPORT EC(x)
8: BEGIN
9: // CAS Custom  Menu
10: // EWS 2014-04-20
11://splashscreen

// ************ A NEW LINE BELOW HERE ******************
WHILE 1 DO // Or similar

12: LOCAL m,m1,mx,my;
13: WHILE MOUSE(1)≥0 DO END;
14: RECT;
15: TEXTOUT_P("How to GOTO?",1,1,4);
16:
17: 
18: DRAWMENU("opt1","opt2","opt3","opt4","opt5","opt6");
19:
20: REPEAT
21: m:=MOUSE;
22: m1:=m(1);
23: UNTIL SIZE(m1)>0;
24: mx:=m1(1);
25: my:=m1(2);
26:
27:
28:
29: IF mx≥0 AND mx≤51 THEN
30: SUB1();
31: END;

...

49: END;

// ************ A NEW LINE BELOW HERE ******************
END; // end while, it will loop to the while as you wanted.

50:
51: END;
52:
53: //SUB1
...

By adding 2 lines : WHILE and corresponding END

It's just a simple implementation, you can improve this by adding a loop condition ( to avoid leaving only by ON key)...

primer
Find all posts by this user
Quote this message in a reply
11-25-2015, 05:17 PM (This post was last modified: 11-25-2015 05:36 PM by jrozsas.)
Post: #6
RE: GO TO? JUMP?
tks primer
tks Han !
its work

Leo

Visit this user's website Find all posts by this user
Quote this message in a reply
11-25-2015, 05:27 PM (This post was last modified: 11-25-2015 05:29 PM by jrozsas.)
Post: #7
RE: GO TO? JUMP?
another REPEAT -- UNTIL 0 also works well.
Code:
SUB1();
SUB2();
SUB3();
SUB4();
SUB5();
SUB6();
EXPORT EC(x)
BEGIN
// CAS Custom Menu
// EWS 2014-04-20

REPEAT // this new REPEAT works!
LOCAL m,m1,mx,my;
WHILE MOUSE(1)≥0 DO END;
RECT;
TEXTOUT_P("How to GOTO?",1,1,4);


DRAWMENU("opt1","opt2","opt3","opt4","opt5","Sair");

REPEAT
m:=MOUSE;
m1:=m(1);
UNTIL SIZE(m1)>0;
mx:=m1(1);
my:=m1(2);



IF mx≥0 AND mx≤51 THEN
SUB1();
END;

IF mx≥53 AND mx≤104 THEN
SUB2();
END;

IF mx≥106 AND mx≤157 THEN
SUB3()
END;

IF mx≥159 AND mx≤210 THEN
SUB4();
END;

IF mx≥212 AND mx≤263 THEN
SUB5();
END;

IF mx≥265 AND mx≤319 THEN
SUB6();
END;
UNTIL 0;
END;


//SUB1
SUB1()
BEGIN
RECT;
TEXTOUT_P("PRESS SUB1",1,1,4);
WAIT(2);
END;

//SUB2
SUB2()
BEGIN
RECT;
TEXTOUT_P("PRESS SUB2",1,1,4);
WAIT(2);
END;

//SUB3
SUB3()
BEGIN
RECT;
TEXTOUT_P("PRESS SUB3",1,1,4);
WAIT(2);
END;

//SUB4
SUB4()
BEGIN
RECT;
TEXTOUT_P("PRESS SUB4",1,1,4);
WAIT(2);
END;

//SUB5
SUB5()
BEGIN
RECT;
TEXTOUT_P("PRESS SUB5",1,1,4);
WAIT(2);
END;

//SUB6
SUB6()
BEGIN
KILL;
//RECT;
//TEXTOUT_P("PRESS SUB6",1,1,4);
//WAIT(2);
END;

Leo

Visit this user's website Find all posts by this user
Quote this message in a reply
11-25-2015, 05:29 PM
Post: #8
RE: GO TO? JUMP?
Thanks people!

Leo

Visit this user's website Find all posts by this user
Quote this message in a reply
11-26-2015, 12:05 AM (This post was last modified: 11-26-2015 01:31 AM by ji3m.)
Post: #9
RE: GO TO? JUMP?
Not quite a go to but a jump table way(or should i say call table)

SUB1 () begin .. end ;
...
SUB6 () begin end;


//somewhere in your code
//mx is mouse x position

local jmplist := {'SUB1', 'SUB2', ... 'SUB6'};

// then
....
eval( jmplist ( IP (mx/51) ) ); // a call to one of the subs

//return is here
...
This works nicely for function with no arguments.
The single quotes on the func names are crucial.

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
Post Reply 




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