Page 1 of 1 1
Topic Options
#163829 - 2006-06-29 08:33 PM GOSUB w/o Return?
smwells Offline
Lurker

Registered: 2006-06-29
Posts: 2
I am revamping a logon script, and I noticed they fail to use 'return' at the end of each section, I am wondering if a 'return' is forced when the script hits the next section marker or does the script continue into the next area?

Also they call another gosub from the first, then the 2nd calls 3rd, and so on, but no return statment, instead they gosub to 'exit' subroutine..

Top
#163830 - 2006-06-29 08:45 PM Re: GOSUB w/o Return?
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Might as well use ... g.. goo..."goto" there i said it...

you can use gosub with out a return, not recommended... but you can do it. it will not force a return and just keep running the script... until it hits another gosub telling it to go someplace else.

Functions, Functions, Functions.... a lot cleaner than gosub/goto...

Bryce

Top
#163831 - 2006-06-29 08:50 PM Re: GOSUB w/o Return?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
gotta love spaghetti
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#163832 - 2006-06-29 08:51 PM Re: GOSUB w/o Return?
smwells Offline
Lurker

Registered: 2006-06-29
Posts: 2
I am planning a complete rewrite, but need to walk the existing one to see how it works.. (works.. hmm, a very grey area!!!)
Top
#163833 - 2006-06-29 08:56 PM Re: GOSUB w/o Return?
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Quote:

I am planning a complete rewrite, but need to walk the existing one to see how it works.. (works.. hmm, a very grey area!!!)




Code:

? "hello 1"
gosub 1
? "hello 2"
? "hello 3"
1:
? "hello 4"
2:
? "hello 5"
gosub exit
? "hello 6"
? "hello 7"
? "hello 8"
:exit



take the above code...

when ran... you get

hello 1
hello 4
hello 5

Top
#163834 - 2006-06-29 11:09 PM Re: GOSUB w/o Return?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
You can use the /D switch to debug and walk through the code but that could take a while too.

Without RETURN then the GOTO statements will not return but will continue on as Bryce has shown. If the script is not sensitive in nature or too long perhaps you could post it here and I'm sure someone will help you take a crack at fixing it up properly.

Without RETURNS the code can't be working very well as it is, so not much harm done in re-organizing it.

What version of KiXtart are you using?

Top
#163835 - 2006-06-30 08:29 AM Re: GOSUB w/o Return?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany


Yummie !!!
_________________________



Top
#163836 - 2006-06-30 10:29 AM Re: GOSUB w/o Return?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

I am wondering if a 'return' is forced when the script hits the next section marker




No, there is no implicit return.

If the return is missing the script will drop through and execute the next section.

Also, if there is no exit in the main code, then the script will drop into the subroutines and exit them.

There are some uses for this technique, but they are exceptional and because they make the script so hard to understand and maintain they should be avoided.

Here is a very simple example of your current scenario:
Code:
"In main" ?

GoSub "FOO"
GoSub "BAR"

; Subroutines
:Foo
"Now in FOO" ?

:Bar
"Now in BAR" ?
RETURN



The coder is expecting to see "In Main", "Now in FOO" and "Now in BAR" but what we actually get is:
Code:
In main
Now in FOO
Now in BAR
Now in BAR
Now in FOO
Now in BAR


Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 781 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.056 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org