Page 1 of 1

Repeat loops ???

Posted: Fri Jan 28, 2011 7:22 pm
by evopres24
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

Re: Repeat loops ???

Posted: Fri Jan 28, 2011 9:57 pm
by mwieder
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

Re: Repeat loops ???

Posted: Fri Jan 28, 2011 10:09 pm
by dunbarx
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

Re: Repeat loops ???

Posted: Sat Jan 29, 2011 2:08 am
by FourthWorld
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. :)

Re: Repeat loops ???

Posted: Sat Jan 29, 2011 5:34 am
by evopres24
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

Re: Repeat loops ???

Posted: Sat Jan 29, 2011 6:08 am
by mwieder
Ah... now I see what you're up to. That's a clever exponential loop.

Re: Repeat loops ???

Posted: Sat Jan 29, 2011 7:44 pm
by dunbarx
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

Re: Repeat loops ???

Posted: Sun Jan 30, 2011 2:28 pm
by BvG
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.

Re: Repeat loops ???

Posted: Sun Jan 30, 2011 7:45 pm
by dunbarx
I ain't no teacher.

Craig