repeat with if
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
repeat with if
Hi,
I need a loop (with many lines of code inside) acting in ascending or descending order depending on the state of an external button.
How do I do it without creating two loops duplicating all the code?... ie acting only on the head?
Something like this does not seem to work:
-------------
on mouseUp
if not the hilite of button "reverse" then repeat with a = 1 to 200
if the hilite of button "reverse" then repeat with a = 200 down to 1
## code
end repeat -- ???
end repeat -- ???
end mouseUp
-------------
Thank you
I need a loop (with many lines of code inside) acting in ascending or descending order depending on the state of an external button.
How do I do it without creating two loops duplicating all the code?... ie acting only on the head?
Something like this does not seem to work:
-------------
on mouseUp
if not the hilite of button "reverse" then repeat with a = 1 to 200
if the hilite of button "reverse" then repeat with a = 200 down to 1
## code
end repeat -- ???
end repeat -- ???
end mouseUp
-------------
Thank you
Re: repeat with if
Hola Fermin,
you cannot nest the loops this way
If I understood your problem correctly, this should do it:
Best
Klaus
you cannot nest the loops this way

If I understood your problem correctly, this should do it:
Code: Select all
on mouseUp
if the hilite of btn "reverse" then
repeat with a = 200 down to 1
## do your reverse repeat stuff here...
end repeat
else
repeat with a = 1 to 200
## do your repeat stuff here...
end repeat
end if
end mouseUp
Klaus
Re: repeat with if
Well, one quick way:
HTH,
Thierry
Code: Select all
on mouseUp
get the hilite of me button "reverse"
if IT is true then
repeat with a = 1 to 20
yourcode a
end repeat
else
repeat with a = 20 down to 1
yourcode a
end repeat
end if
end mouseUp
on yourcode a
# ...
end yourcode
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: repeat with if
Hallo Klaus,
Once again you're faster
Once again you're faster

!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: repeat with if
Thanks, Thierry and Klaus, but the inner code is the same in both cases. I do not want to repeat it. I would like to work by changing just the first line.
[Repeat with a = 1 to 200] vs [repeat with a = 200 down to 1]
... but it may not be possible.
[Repeat with a = 1 to 200] vs [repeat with a = 200 down to 1]
... but it may not be possible.
Re: repeat with if
well, putting the inner code in a handler,Fermin wrote:Thanks, Thierry and Klaus, but the inner code is the same in both cases.
then you have only one time your code!
Code: Select all
on yourcode a
# ...
end yourcode

Or what did I miss?
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: repeat with if
Good idea, but the handler must to have many local/global variables ...
I think I've found a solution that seems to serve:
Thank you very much
I think I've found a solution that seems to serve:
Code: Select all
on mouseup
-- the main variable is 'a'
repeat with b = 1 to 200
put b into a -- normal mode
if the hilite of button "reverse" then put 200-b into a -- reverse mode
-- here the code related with variable 'a'
end repeat
end mouseup
Thank you very much
Re: repeat with if
If the script produces any kind of list, it might be possible to run the handler normally and then reverse sort the list after the loop completes if the Reverse button is hilited.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com