#70239 - 2002-09-24 07:29 PM
GOTO/Endfunction BUG
|
Howard Bullock
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
|
Top
|
|
|
|
#70240 - 2002-09-24 08:42 PM
Re: GOTO/Endfunction BUG
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
the only thing I can say is...... don't use Goto
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
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.
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. [ 24. September 2002, 21:08: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 507 anonymous users online.
|
|
|