Temporarily stopping a loop
Author |
Message |
AK.E
|
Posted: Sat Jan 13, 2007 7:11 pm Post subject: Temporarily stopping a loop |
|
|
Just what the title says. Is there a way to stop a loop while you're doing something else?
An example of what I'm trying to achieve is below
code: | procedure tiger
put "Yes... the tiger is the greatest animal!"
end tiger
loop
var animal : string
get animal
if animal = "tiger" then
tiger
end if
end loop
|
The problem with this is that the moment it says "Yes... the tiger is the greatest animal!" it automatically goes back to the beginning of the loop. Is there a way to stop the loop then start it again within the procedure. Or is there a better way of achieving what I'm trying to do? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
avsrule247
|
Posted: Sat Jan 13, 2007 8:20 pm Post subject: Re: Temporarily stopping a loop |
|
|
If you want to exit the loop completely you can just put "exit" within the if statement. However, if you want to ask the question again after you do something else then you would do:
code: |
loop
loop
var animal : string
get animal
if animal = "tiger" then
tiger
exit
end if
end loop
var name : string
get name
put "Your name is: ", name
end loop
|
That will ask for the animal, temporally stop the loop, do something else (like ask for your name) then it will go back into the animal loop. |
|
|
|
|
|
Cervantes
|
Posted: Sat Jan 13, 2007 10:16 pm Post subject: RE:Temporarily stopping a loop |
|
|
Sure, you can pause execution. What you're really doing though, is executing a command that stalls. get is one of these, because it waits for user input. I think what you're looking for is Input.Pause, which will pause until a keystroke is pressed. |
|
|
|
|
|
AK.E
|
Posted: Sat Jan 13, 2007 10:48 pm Post subject: Re: Temporarily stopping a loop |
|
|
Thanks a lot you guys. It helped a lot. |
|
|
|
|
|
|
|