Repeat loops ???

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
evopres24
Posts: 2
Joined: Fri Jan 28, 2011 7:15 pm

Repeat loops ???

Post by evopres24 » Fri Jan 28, 2011 7:22 pm

How do you go about writing a script that could carry out multiplication with a series of addition operations. Using a repeat loop to carry out the "repeated" additions. Included with nested repeat loops for the repeated multiplication

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Repeat loops ???

Post by mwieder » Fri Jan 28, 2011 9:57 pm

This looks like a class assignment, so I won't give you the answer, but here are some hints:

1. Read the documentation, especially the "repeat" command in the online Dictionary.
2. See step 1

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

Re: Repeat loops ???

Post by dunbarx » Fri Jan 28, 2011 10:09 pm

I hate wiseguys, don't you? Especially when they post before I do.

If you are asking because you are at the very beginning stages of learning LC, then Mark is right, you need to work it out yourself. But know that you do not nearly need any nesting. A single repeat loop of 3 lines will do, and that includes the two keyword lines. 90% of your script will deal with data entry and displaying the sum.

If you really are stuck ask again. But do try.

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10048
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Repeat loops ???

Post by FourthWorld » Sat Jan 29, 2011 2:08 am

mwieder wrote:This looks like a class assignment, so I won't give you the answer, but here are some hints:

1. Read the documentation, especially the "repeat" command in the online Dictionary.
2. See step 1
The instructions on my shampoo bottle read, "Lather, rinse, repeat" - went through that bottle pretty fast. :)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

evopres24
Posts: 2
Joined: Fri Jan 28, 2011 7:15 pm

Re: Repeat loops ???

Post by evopres24 » Sat Jan 29, 2011 5:34 am

nvm this is what I did...
on mouseUp
put field "Field 1" into x
put field "Field 2" into y
put 0 into multResult
repeat until y = 0
put (multResult +x) into multResult
put (y-1) into y
end repeat
put multResult into field "Field 3"
end mouseUp

(this is for multiplication)

on mouseUp
put field "Field 1" into x
put field "Field 2" into y
put x into multResult
repeat until y = 1
put field "Field 1" into base
repeat until base=1
put (multResult + x) into multResult
put (base-1) into base
end repeat
put multResult into x
put (y-1) into y
end repeat
put multResult into field "Field 3"
end mouseUp

here is a nested loop for exponentials

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Repeat loops ???

Post by mwieder » Sat Jan 29, 2011 6:08 am

Ah... now I see what you're up to. That's a clever exponential loop.

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

Re: Repeat loops ???

Post by dunbarx » Sat Jan 29, 2011 7:44 pm

We must put an end to the madness,

on mouseUp
ask "What is the first number?" --not sure where you are getting your numbers from
put it into arg1
ask "What is the second number?"
put it into arg2 --Hmmm. What happens if we put an "A" here instead of a number??
put 0 into tAnswer --Hmmm, do we really need this?

repeat arg1
add arg2 to tAnswer
end repeat

answer tAnswer
end mouseUp

The repeat loop itself is only, really, one line. All the rest is lagniappe. But really think about the little annoying comments I added. Try to break the script with that "A". You are on your way....

Craig Newman

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: Repeat loops ???

Post by BvG » Sun Jan 30, 2011 2:28 pm

This post reminds me how a disproportionally large amount of LiveCode users are teacher or otherwise educational-employed.

This post also shows why that is a good thing.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

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

Re: Repeat loops ???

Post by dunbarx » Sun Jan 30, 2011 7:45 pm

I ain't no teacher.

Craig

Post Reply