Ok, lets get into this.
I mentioned in another tutorial that I'd talk about Repeat/Until and While. And he it is.
Both will do whatever follows over and over until a condition is met.
Lemme show you an example of both.
repeat
check the amount of beer in Cerv's glass
until the amount of beer in Cerv's glass = 0
See how whatever the until line is checking for has to be done in between the repeat-until? Now to do that with a while statement we have to check first, then check again inside.... watch
check the amount of beerin Cerv's glass
while the amount of beer <> 0
{
Cerv chills out and drinks beer
check the amount of beerin Cerv's glass
}
See how the while statement needed to check the glass both before and during the statement to see if it met criteria?
In that case, using Repeat/Until makes much more sense.
Here's Cerv's Rules For Using Repeat/Until or While:
If I'm checking something that I have set in the script - use Repeat/Until.
If I'm checking for something that EUOx sets - use While.
What that means is like in the example above. I'm checking for something that I have setup in the script. So I would use the Repeat/Until.
Now here's when I like to use While.
repeat
do this thing that requires mana
until #mana < 10
See that will repeat whatever is in the middle until my mana drops below 10. Since #mana is an EUOx function thingy, I like to use While for this.
while #mana > 10
do this thing that requires mana
You can see the difference right there. If it's a # command from EUOx I always prefer to use While because I don't have to constantly check whatever is the criteria in the statement.
Another thing to remember when using repeat/until and while.
Repeat/Until will do everything in between them. Everything.
repeat
do this
do that
do the other
do some more
until #done
With While it will only do the NEXT LINE OF CODE unless you use brackets {}
while something is something
do this
do that
do the other
do some more
That code will ONLY do the one line under the while (do this) until the criteria is met (something is something). The correct usage would be:
while something is something
{
do this
do that
do the other
do some more
}
By putting everything in brackets they will all be done until the criteria is met.
That's about it. Hopefully it'll spark some conversation.
Key Points:
1 - Use Cerv's Rules, use repeat/until if I set it, use while if EUOx sets it.
2 - Repeat does everything between it and Until, While does the next line or between the brackets {}