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

Post Reply
gilar
Posts: 96
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
Gilar | from INDONESIA

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9645
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”