I have code like this
repeat with i = theTotal to 1 step -1
if z < 29 then
put hArray into uhArray[z]
add 1 to z
else
put theTotal into i
end if
end repeat
z = 1 at the start.
theTotal > 50
hArray contains a list of numbers (not
consecutive) and I want to get the last 28
unique numbers so that I can get the
unused numbers. (The code above doesn't
detect repeat numbers).
The question is "Why does the loop keep
repeating after theTotal is put into i?
It should come out of the repeat loop, I feel.
This is the only way I can see to exit the loop
without making it into a separate handler. It's
something I've used in other languages with no
problems.
Any ideas welcome including how to detect
duplicates and not put them into uhArray a
second time.
Perhaps a field is the answer but should be
able to do it with arrays.
Stuck in a loop?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Stuck in a loop?
Life is just a bowl of cherries.
The loop seems to repeats from theTotal down to 1, so it'll exit when x = 1 or less, not when it's the same as theTotal (it would exit immediately in that case).
I'd suggest using "exit repeat" in your if/else statement, that'll be easier to follow and cleaner to read. Barring that, set x to 1 and it'll stop repeating.
If you just care for the unique numbers, but not the order, then i suggest this:
I'd suggest using "exit repeat" in your if/else statement, that'll be easier to follow and cleaner to read. Barring that, set x to 1 and it'll stop repeating.
If you just care for the unique numbers, but not the order, then i suggest this:
Code: Select all
split listOfNumbers by return and tab --there can be no tab in listOfNumbers
put the keys of listOfNumbers into listOfNumbers
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
Stuck in a loop?
Of course! Set x to 1 not to theTotal.
Can't understand how I missed finding
"exit repeat".
Unfortunately the order is important in
this case so really need to be able to
get the number of the array element
that a particular number's in.
Can't find a way to get at that.
Say theArray[3] = 29.
29 is the number I want.
How can I record that it's in element 3?
Edit...
Since what I'm looking for is the point
where a certain number of buttons
haven't been clicked I've come to the
conclusion that the only way is to go
from last click sending "mouseUp" to each
button in the list and checking the number
of unclicked buttons after each "mouseUp".
This is going in the reverse direction to
the one required.
When it gets to the point where the required
number of buttons are unclicked I can grab
the array element number and do the same
from there to the last click (i.e. in the right
order).
Might take longer but time isn't really important.
Can't understand how I missed finding
"exit repeat".
Unfortunately the order is important in
this case so really need to be able to
get the number of the array element
that a particular number's in.
Can't find a way to get at that.
Say theArray[3] = 29.
29 is the number I want.
How can I record that it's in element 3?
Edit...
Since what I'm looking for is the point
where a certain number of buttons
haven't been clicked I've come to the
conclusion that the only way is to go
from last click sending "mouseUp" to each
button in the list and checking the number
of unclicked buttons after each "mouseUp".
This is going in the reverse direction to
the one required.
When it gets to the point where the required
number of buttons are unclicked I can grab
the array element number and do the same
from there to the last click (i.e. in the right
order).
Might take longer but time isn't really important.
Life is just a bowl of cherries.
Try this ...
Code: Select all
on mouseUp
put 19 into myArray[5]
put 29 into myArray[4]
put 39 into myArray[3]
put 49 into myArray[2]
put 59 into myArray[1]
combine myArray by row
put myArray & cr & 29 && "is in array element" && lineOffset(29, myArray)
end mouseUp