If, else, endif problem

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm

Re: If, else, endif problem

Post by liveme » Tue Feb 23, 2021 9:12 pm

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" :shock: :lol:

I have just modified Thierrys code by adding the word "field"before of N ... :D ..thats was hard ! :D

@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
Image
Attachments
IFA PROCESS.png
IFA PROCESS.png (6.03 KiB) Viewed 2950 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: If, else, endif problem

Post by dunbarx » Wed Feb 24, 2021 9:13 pm

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

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm

Re: If, else, endif problem

Post by liveme » Wed Feb 24, 2021 9:47 pm

Thanks graig....yop,
though I already skip lunch yesterday :D 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

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: If, else, endif problem

Post by Klaus » Wed Feb 24, 2021 10:01 pm

No, REPEAT in LC is the keyword for a LOOP that will follow.
An equivalent to FOR in other languages may be WITH:

Code: Select all

...
repeat WITH i = 1 to 42
...
P.S.
Mr. dunbarx name is Craig! 8)

SparkOut
Posts: 2946
Joined: Sun Sep 23, 2007 4:58 pm

Re: If, else, endif problem

Post by SparkOut » Wed Feb 24, 2021 10:20 pm

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.

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: If, else, endif problem

Post by stam » Wed Feb 24, 2021 11:00 pm

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...

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm

Re: If, else, endif problem

Post by liveme » Thu Feb 25, 2021 1:26 am

Repeat to user Craig or else :
put Thanks a lot For Each Reply
:P

Post Reply