LoginLogin

What's up with this?

Root / Programming Questions / [.]

spaceturtlesCreated:
Slot 0:
OPTION STRICT
EXEC 1
USE 1

A "FHFYFYF","FYYFUFH",3,6,8
Slot 1:
OPTION STRICT

VAR _I%

DIM A$[0]
DIM B$[0]
DIM A%[0]
DIM B%[0]
DIM C%[0]

COMMON DEF A _A$,_B$,_A%,_B%,_C%
 FOR _I%=LEN(A$)-1 TO 0 STEP -1
  IF A$[_I%]==_A$ THEN
   _A$=_A$+"_"
   BREAK
   ENDIF
  NEXT
 
 PUSH A$,_A$
 PUSH B$,_B$
 PUSH A%,_A%
 PUSH B%,_B%
 PUSH C%,_C%
 END
Results with a type mismatch in 1:12. Why?

Would it be because LEN(A$) already equals 0? So when you
FOR _I%=LEN(A$)-1 TO 0 STEP -1
LEN(A$)-1 would be -1 and you are trying to increase it by -1 to get to 0 when you should increase by +1, unless I am misreading. EDIT: I think if the array was larger it might work. It's interesting to see the _I%=LEN rather than LEN being the condition to end the loop, so it is a little confusing to me.

Problem solved; USE 1 in slot 0 was not required and had to be removed.
Would it be because LEN(A$) already equals 0? So when you
FOR _I%=LEN(A$)-1 TO 0 STEP -1
LEN(A$)-1 would be -1 and you are trying to increase it by -1 to get to 0 when you should increase by +1, unless I am misreading. EDIT: I think if the array was larger it might work. It's interesting to see the _I%=LEN rather than LEN being the condition to end the loop, so it is a little confusing to me.
Kinda. When the loops begins with a number that is "beyond" the target number it doesn't execute.

Problem solved; USE 1 in slot 0 was not required and had to be removed.
Would it be because LEN(A$) already equals 0? So when you
FOR _I%=LEN(A$)-1 TO 0 STEP -1
LEN(A$)-1 would be -1 and you are trying to increase it by -1 to get to 0 when you should increase by +1, unless I am misreading. EDIT: I think if the array was larger it might work. It's interesting to see the _I%=LEN rather than LEN being the condition to end the loop, so it is a little confusing to me.
Kinda. When the loops begins with a number that is "beyond" the target number it doesn't execute.
Ah okay thanks. I didn't know it didn't execute, I thought it would've produced an error.

(anyway the problem was that he was calling the function before the arrays had been created) EDIT: (replace EXEC 1:USE 1 with just EXEC 1)