Hello!
I’m trying to figure out if it is possible to nest an “if” inside a “for” in the debugger?
This works:
for each i in m.var: print i: end for
Now I want something like this
for each i in m.var
if i = "something"
? i
end if
end for
So far no matter what I’ve tried I get back
A block (such as FOR/NEXT or IF/ENDIF) was not terminated correctly. (compile error &hb5) in $LIVECOMPILE(256)
Tried these and more:
for each i in m.var : if i = "something" then ? i: end for
&
for each i in m.var : if i = "something" then ? i: end if : end for
&
for each i in m.var : if i = "something" : ? i : end if : end for
Anyone know how to do this, is it possible?
tyvmia
items = ["one","two","three"]
? type(items)
for each i in items
if i <> ""
? i
end if
end for
roArray
one
two
three
Is type(m.var) always “roArray” or “roAssociativeArray”?
Komag
December 19, 2016, 9:55pm
3
I would have thought the last attempt would have worked, but in my own tests I see it doesn’t
for each i in m.var : if i = "something" : ? i : end if : end for
So I dunno what can be done.
EnTerr
December 20, 2016, 4:38am
4
yeah, it won’t work, since the parser makes assumptions - have to decide which form of if is used - and then it does not backtrack.
i think at some point i came with a very contrived way to accomplish something like the asked… except can’t remember now. Ooops.
PS. Behold! I just devised you a new Rube Goldberg machine :
Brightscript Debugger> tbl = ["r", "a", "n", "d", "o", "m"]: for i = 0 to tbl.count()-1: ? {false:"", true: i.toStr() + chr(10)}[(tbl[i] > "m").toStr()]; : next
0
2
4
PPS. perhaps my old idea was
tbl = ["r", "a", "n", "d", "o", "m"]: for i = 0 to tbl.count()-1: while tbl[i] > "m": ? i: exit while: end while: next