06-28-2009, 07:42 AM
For...Next Loop:
Here is the syntax of a for...next loop:
for var variable name condition start value to stop value
...
next
Here is an example of how you use this:
The first number of a for loop must always be 0. If you don't set it to 0 you will get a an error when running your script. The second number is how many times this loop will run. Remember, that since we have to start at 0 the above loop will say hi! 5 times and not 4 times (0,1,2,3,4 is 5 loops). The counter will automatically increase for you when your script reaches the next line.
While...Wend Loop:
Here is the syntax of a while...wend loop:
while variable condition stop value
...
wend
Here is an example of how you use this:
This loop will check how many times it ran when it gets to the first line. If the condition is not true it will exit. Since we set the counter to 1 instead of 0 before starting the loop and tell it to stop before it reaches 5, it will say hi! 4 times. Unlike with the for loop we have to increase the counter ourselves since there's no next line to do it for us.
If you want a loop to run for an unknown amount of loops, you can make an infite while loop by saying while 1 or while true instead of using a counter.
Repeat...Until Loop:
Here is the syntax of a repeat...until loop:
Repeat
...
until property condition stop value
Here is an example of how you use this:
This loop will check how many times it ran at the end of the loop so it will always run at least 1 time. Like with the other loops, this loop will exit if the condition is not true when it's checked. Like with the while...wend loop we have to increase the counter ourselves since there's no next line to do it for us. You should also notice the exit condition here (counter > 5) is the opposite of the exit condition in the while loop (counter < 5).
Throughout all my loops you'll notice how parts of the text are indented. This is done to help you see where your loops begin and end. I highly recommend you do this when making your own!
More to come after I play with Injection some more and get some sleep!
Here is the syntax of a for...next loop:
for var variable name condition start value to stop value
...
next
Here is an example of how you use this:
PHP Code:
for var counter = 0 to 4
uo.say("hi!")
wait (1000)
next
The first number of a for loop must always be 0. If you don't set it to 0 you will get a an error when running your script. The second number is how many times this loop will run. Remember, that since we have to start at 0 the above loop will say hi! 5 times and not 4 times (0,1,2,3,4 is 5 loops). The counter will automatically increase for you when your script reaches the next line.
While...Wend Loop:
Here is the syntax of a while...wend loop:
while variable condition stop value
...
wend
Here is an example of how you use this:
PHP Code:
var counter = 1
while counter < 5
uo.say("hi!")
wait(1000)
counter=counter+1
wend
This loop will check how many times it ran when it gets to the first line. If the condition is not true it will exit. Since we set the counter to 1 instead of 0 before starting the loop and tell it to stop before it reaches 5, it will say hi! 4 times. Unlike with the for loop we have to increase the counter ourselves since there's no next line to do it for us.
If you want a loop to run for an unknown amount of loops, you can make an infite while loop by saying while 1 or while true instead of using a counter.
Repeat...Until Loop:
Here is the syntax of a repeat...until loop:
Repeat
...
until property condition stop value
Here is an example of how you use this:
PHP Code:
var counter=1
Repeat
uo.say("hi!")
wait(1000)
counter=counter+1
until counter>5
This loop will check how many times it ran at the end of the loop so it will always run at least 1 time. Like with the other loops, this loop will exit if the condition is not true when it's checked. Like with the while...wend loop we have to increase the counter ourselves since there's no next line to do it for us. You should also notice the exit condition here (counter > 5) is the opposite of the exit condition in the while loop (counter < 5).
Throughout all my loops you'll notice how parts of the text are indented. This is done to help you see where your loops begin and end. I highly recommend you do this when making your own!
More to come after I play with Injection some more and get some sleep!
