|
AKstorm Newbie
Joined: 31 May 2003 Posts: 3 Location: Brazil
|
Posted: Thu Jun 05, 2003 7:02 am
How to stop/break #loop ? |
If I have a #loop running, is there a way to break it from executing?
|
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Thu Jun 05, 2003 1:03 pm |
There's no simple way of doing this. You are going to have to set a control variable to true and have the rest of the loop check to see if it is true. If it is, execute no other commands. Then add a check at the conditional for the loop so that the loop ends as soon as the control variable is true.
Kjata |
|
|
|
Zafrusteria Wanderer
Joined: 11 Oct 2000 Posts: 94 Location: United Kingdom
|
Posted: Thu Jun 05, 2003 3:23 pm |
You can use #ABORT or #ABORT 1 have a look at the manual pages to see which one you need.
If it is in a loop that you want to stop at some point regardless of the settings or number of times it has run, say the boss just walked in and you want to change screens :-)
In the loop test a variable for a value as in
#var abort_loop 0
#loop @loop {
#IF (@abort_loop = 1) {#abort 1}
; what ever your loopwas doing already
}
now just set @abort _loop to 1 and your loop will stop the next time round.
Hope that helps.
Zaf |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Fri Jun 06, 2003 12:17 am |
#ABORT 1 will stop the whole script which I'm guessing is not what AKstorm wanted. #ABORT by itself, without the 1, is just useless since it ends the block of commands it is in, but since you usually use an #IF to break out of a loop, the #ABORT will just end the #IF and not the loop.
Kjata |
|
|
|
AKstorm Newbie
Joined: 31 May 2003 Posts: 3 Location: Brazil
|
Posted: Fri Jun 06, 2003 1:21 pm |
Thanks guys
I did it Zafs way seems to only kill the if. its good enough but might be better to kill the loop itself.
Kjata can you exemplify your idea? I got the concept but cant seem to think on how to write it |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Fri Jun 06, 2003 5:42 pm |
Sure:
#VAR abort 0
#WHILE (!@abort and (my loop condition)) {do stuff;#IF (some condition) {#VAR abort 1};#IF (!@abort) {other commands in the loop}}
This way, when the condition in the #IF is true (which is when you want to break), it sets the @abort variable to true. The rest of the loop is only executed if the @abort variable is false, and as soon as the current iteration ends, the condition of the loop will no longer be true and the loop exits. This process would mimic a break statement.
Kjata |
|
|
|
|
|