Multiple Variable on Repeat Functrion .... ?

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: heatherlaine, Klaus, FourthWorld, kevinmiller

Post Reply
gilar
Posts: 78
Joined: Sat Sep 26, 2015 12:59 pm

Multiple Variable on Repeat Functrion .... ?

Post by gilar » Sat Sep 22, 2018 4:17 am

From what i know ... Repeat function usually only one variable
ex:
repeat with i = 1 to 12
--------
end repeat
Is it possible to put 2 or more variable on repeat function?
ex:

repeat with i = 1 to 10, and j with = 10 to 20 (try this code but no luck)
--------
end repeat

this is my code

Code: Select all

on mouseUp
   repeat with i = 1 to 12
         put "<componentData id=\"& quote&"tName"&i&"\"&quote&"><data id=\"&quote&"text\"&quote&" value=\"&quote&"tValue"&i&"\"&quote &"/></componentData>" into field test_fld
   end repeat
end mouseUp

Comment and help would be appriciate


Best Regards



Gilar Kadarsah

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6155
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Multiple Variable on Repeat Functrion .... ?

Post by FourthWorld » Sat Sep 22, 2018 4:21 am

Since the range within a loop is the same, you can maintain the var j within the loop by just adding to i:

Code: Select all

repeat with i = 1 to 10
   put i+9 into j
   DoSomethingWith i,j
end repeat
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5528
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Multiple Variable on Repeat Functrion .... ?

Post by dunbarx » Sat Sep 22, 2018 3:40 pm

Or you can nest the loops:

Code: Select all

on mouseUp
   repeat with y = 1 to 10
  repeat with x = 1 to 10
      put y & comma & x & return after accum
    end repeat
 end repeat
 put accum into fld 1
end mouseUp
You can nest farther if you need to...

Craig Newman

EDIT: I have gone as far as four levels. It wasn't my fault.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”