|
GOTO
Oct 31, 2021 12:41:48 GMT -6
Post by johnno56 on Oct 31, 2021 12:41:48 GMT -6
I know, I know... in some circles GOTO is never discussed. Apart from my dislike of the function, particularly when it comes to converting 'other' Basic's, I have noticed that some Basics still use GOTO... Is there any particular reason as to why it was not included in RCBasic? Not a criticism. Just curious.
|
|
|
GOTO
Oct 31, 2021 14:04:13 GMT -6
Post by aurel on Oct 31, 2021 14:04:13 GMT -6
wow...no goTo in rcbasic I don't know that ?? about goto ...i think that everyone who claim that goto sucks is a just freakin delusion ask any assembly coder what about jump...
|
|
|
GOTO
Oct 31, 2021 14:13:59 GMT -6
Post by johnno56 on Oct 31, 2021 14:13:59 GMT -6
Aurel, I will have to take your word for that... I know almost nothing of assembler...
|
|
|
GOTO
Nov 1, 2021 3:57:44 GMT -6
Post by aurel on Nov 1, 2021 3:57:44 GMT -6
I used jmp in oxygen basic as goto ..because it is same in o2 which is assembler with basic syntax
|
|
|
GOTO
Nov 1, 2021 6:02:48 GMT -6
Post by n00b on Nov 1, 2021 6:02:48 GMT -6
The main reason why GOTO won't work well in RCBasic is because of the stack.
When you create a function, it pushes the value of all the internal registers to the stack. So lets say you decided to GOTO a line inside a function or from within a function GOTO a line outside a function. You would either end up trying to pop a value that was never pushed or push a value that is never popped. The first example would crash your program. The second one wouldn't but if you have this happening in a loop over and over you are going to end up with a stack that is constantly be filled and never being emptied which will cause you to run out of RAM.
GOTO and GOSUB work well for languages that don't have user defined functions and sub procedures like assembly and BASIC on computers back in the 80s but they don't allow you to do anything that couldn't be done with functions.
|
|
|
GOTO
Nov 1, 2021 6:19:28 GMT -6
Post by rosy on Nov 1, 2021 6:19:28 GMT -6
GOTO is used by many Basic dialects having functions and procedures. If this happens inside a routine, a special instruction is usually used instead of a GOTO. GOSUB is usually a subroutine call, RCBasic does the same without the word GOSUB.
|
|
|
GOTO
Nov 1, 2021 14:21:50 GMT -6
Post by johnno56 on Nov 1, 2021 14:21:50 GMT -6
Thanks n00b. Understood. Converting some GOTO's I can do... But the ones that pop up in For...Next loops... I have no idea. There are a lot of cool games (imho) that I would like to convert to RC but those pesky goto's can be quite annoying... But that's a story for another time... Thanks for the assist.
|
|
|
GOTO
Nov 1, 2021 15:16:34 GMT -6
Post by rosy on Nov 1, 2021 15:16:34 GMT -6
Then throw in an example and we'll think ...
|
|
|
GOTO
Nov 1, 2021 23:30:22 GMT -6
Post by johnno56 on Nov 1, 2021 23:30:22 GMT -6
I will look for one... But I have a LOT of basic listings...I know that I have examples but trying to recall the program name(s) is not easy... I will send something as soon as I can find some...
|
|
|
GOTO
Nov 1, 2021 23:56:53 GMT -6
Post by johnno56 on Nov 1, 2021 23:56:53 GMT -6
This is part of a text adventure game written in Locomotive Basic (Amstrad)
740 : 750 FOR Y=1 TO LEN(W$):IF MID$(W$,Y,2)=A$ THEN F=(Y+1)/2:GOTO 770 760 NEXT Y:F=0 770 FOR X_1 TO LEN(O$) STEP 3:IF MID$(O$,X,3)=B$ THEN S=INT((X+2)/3):GOTO 790 780 NEXT X:IF (S>45 OR S<1) AND B$<>"" THEN F=-1 790 IF F<1 OR F>10 THEN PRINT"What the hell Mac!":GOTO 1080
Line 770: Normally, if it wasn't for the 'F=0' after the NEXT on line 760, I would have replaced the GOTO on line 750 with an 'EXIT FOR'
A similar situation with line 770. if it wasn't for the 'IF (S>45 OR S<1) AND B$<>"" THEN F=-1' after the NEXT in line 780, I would have replaced the GOTO on line 770 with an 'EXIT FOR'
Perhaps instead of using For..Next, maybe the use of INSTR$() to detect the piece of string?
It just doesn't seem right to 'jump' out of a for...next loop. It's obvious that the loop is looking for the first instance of two characters in W$ that equal A$ and the first instance of three characters of O$ that equal B$...
Maybe this was a poor example... I will keep looking...
|
|
|
GOTO
Nov 2, 2021 1:16:17 GMT -6
Post by rosy on Nov 2, 2021 1:16:17 GMT -6
Here you can use Instr. Generally you can use ExitFor and e.g. use an additional variable saying whether exit was used or a FOR loop has come to an end.
|
|
|
GOTO
Nov 2, 2021 4:16:12 GMT -6
Post by aurel on Nov 2, 2021 4:16:12 GMT -6
I agree with you Johnno...goto translation to subroutine can be very tricky in some translation almost impossible I have in my interpreter GOTO but as nOOb says in interpreter is ordinary jump but i have GOTO-> LABEL where each LABEL have its own unique location like SUB location and work similar
|
|