Repeat loops ???
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Repeat loops ???
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 ???
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
1. Read the documentation, especially the "repeat" command in the online Dictionary.
2. See step 1
Re: Repeat loops ???
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
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
-
- VIP Livecode Opensource Backer
- Posts: 10048
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Repeat loops ???
The instructions on my shampoo bottle read, "Lather, rinse, repeat" - went through that bottle pretty fast.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

Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Repeat loops ???
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
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 ???
Ah... now I see what you're up to. That's a clever exponential loop.
Re: Repeat loops ???
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
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 ???
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.
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
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Re: Repeat loops ???
I ain't no teacher.
Craig
Craig