Page 1 of 1 1
Topic Options
#70239 - 2002-09-24 07:29 PM GOTO/Endfunction BUG
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
The code below demonstrates a bug when using GOTO within nested FOR loops inside a UDF. The GOTO takes code executon out of the nested loops. Execution continues until the the ENDFUNCTION statement is hit. Then the code jumps back into the first FOR loop. The second (inside loop) seems to have been killed by the GOTO.

code:
Function C
dim $s, $t, $u, $array1[5]
$s = "Text from Function 'C'"
$array1 = "1","2","3","4","5","6"
for each $t in $array1
for each $u in $array1
? "U = " + $u + " T=" + $t
Goto LabelC
? "After Goto LabelC"
? "U2= " + $u + " T=" + $t
next
next
:LabelC
? $s ?
$C = $s
;exit
Endfunction
? ?
"function C = " + C

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70240 - 2002-09-24 08:42 PM Re: GOTO/Endfunction BUG
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
the only thing I can say is...... don't use Goto [Big Grin]

For controlled exit from a FOR loop walking an array, use the array size as the upper bound of the loop. If a special event is reached in the array, set the for loop variable to equal the upper bound of the loop.

code:
$array = 1,2,5,7,"*",10

;this will walk the array stopping when it reaches the *
for $i = 0 to ubound($array)
;If the array meets this rule exit the for loop
if $array[$i] = "*"
$i = ubound($array)
else
? $array[$i]
endif
next

Bryce

Top
#70241 - 2002-09-24 08:48 PM Re: GOTO/Endfunction BUG
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Can't do that using a "for each" loop construct. Anyway I don't use GOTO's unless it is required to reduce my KixGolf score. [Big Grin]

This should not happen. The "EXIT" to fix it cost me 4 strokes.

One could view this as a feature it they wanted to selectively kill and jump out of a particular nested loop level, execute code, and then jump back into the nested structure, but I would advise it. [Wink]

[ 24. September 2002, 21:08: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70242 - 2002-09-24 08:51 PM Re: GOTO/Endfunction BUG
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Bryce,
generally I have to agree with you. Your example is a pretty simple one. I have seen loops however, that you cannot exit gracefully.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#70243 - 2002-09-24 08:56 PM Re: GOTO/Endfunction BUG
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
This bring us back to this...

Topic: exit do, exit for, exit while, continue
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.051 seconds in which 0.023 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