Page 2 of 2
Re: If, else, endif problem
Posted: Tue Feb 23, 2021 9:12 pm
by liveme
Thierry wrote: Tue Feb 23, 2021 9:44 am
Code: Select all
put 0 into fld "IFA"
repeat with N=1 to the number of fields in group "gFields"
if fld N of group "gFields" is empty then
put N into field "IFA"
exit repeat
end if
end repeat
Thanks thierry for this tip !
I didn't know how to create a "loop"
I have just modified Thierrys code by adding the word "field"before of N ...

..thats was hard !
@trags, I've only tested it on 3 empty/full fields (as on picture) but its efficient where ever the first empty field is.
Code: Select all
on mouseUp pButtonNumber
put " " into field "IFA"
put 0 into numero
repeat with numero=1 to 3 # Modify 3 with your real number of fields..7?"
put "field"&numero into combinedfield # Combining each Numero to create each field's names
if field combinedfield is empty then
put " EXEC.f:"&numero after field "IFA"
# do your magic for IFA here
break # stops once empty field is found
else
# line below can de deleted if no action is required
put " skip f:"&numero after field "IFA"
end if
end repeat
end mouseUp

Re: If, else, endif problem
Posted: Wed Feb 24, 2021 9:13 pm
by dunbarx
Hi.
I didn't know how to create a "loop"
Right now go and play with the "repeat" control structure. Skip dinner and keep at it. There are several flavors, each with its own pros and cons. You have to have this.
Craig
Re: If, else, endif problem
Posted: Wed Feb 24, 2021 9:47 pm
by liveme
Thanks graig....yop,
though I already skip lunch yesterday

while trying to wrap my head arround the expession FOR.
I was browsing up and down the Docs, and still not sure the FOR words exist in LC as it is used in some other languages...
as in :
For x = A to Z
put "Hello Mr"&x ...
So I guess REPEAT stands "for" FOR in LC, is that correct ?
Thanks
Re: If, else, endif problem
Posted: Wed Feb 24, 2021 10:01 pm
by Klaus
No, REPEAT in LC is the keyword for a LOOP that will follow.
An equivalent to FOR in other languages may be WITH:
P.S.
Mr. dunbarx name is Craig!

Re: If, else, endif problem
Posted: Wed Feb 24, 2021 10:20 pm
by SparkOut
But "for [each]" is part of the pantheon of "repeat" loop structures in the (typically blindingly fast) creation
Code: Select all
repeat for each line tKey in the keys of myArray
--do something with this iteration of tKey
end repeat
Biw, I may be heretical, but I always felt that LiveCode has the "for each" and "with" varieties of loop controls thecwrong way round. I got used to it a long time ago, and even if others agreed, it could never be backwards-compatability compliant to change, but it doesn't seem as natural to me as it should. [code]repeat for i = 1 to 10[/code]seems much more in line with other languages and more natural to me. Also [code]repeat with each item tItem in tString[/code] is (to me) a more intuitive structure to iterate over a non-indexed list.
Re: If, else, endif problem
Posted: Wed Feb 24, 2021 11:00 pm
by stam
SparkOut wrote: Wed Feb 24, 2021 10:20 pm
but I always felt that LiveCode has the "for each" and "with" varieties of loop controls thecwrong way round.
Yeh... pretty much mandatory to use the
repeat for each looping structure - it's so versatile and quick and extremely good with arrays.
I agree the naming is weird, in particular the
with version. In my mind it is still
repeat for x = 1 to N, just have to translate it to
repeat with x = 1 when i'm in LC.
Not sure why they decided on that either, other languages have both
repeat for x = 1... and
repeat for each structures and it works just fine...
Re: If, else, endif problem
Posted: Thu Feb 25, 2021 1:26 am
by liveme
Repeat to user Craig or else :
put Thanks a lot For Each Reply
