Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Injection Guide
#7

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:

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
>

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!


Messages In This Thread
Injection Guide - by Eighty Swords - 06-27-2009, 04:31 AM
Injection Guide - by smoke - 06-27-2009, 09:48 AM
Injection Guide - by imported_ScareCrow - 06-27-2009, 03:47 PM
Injection Guide - by Eighty Swords - 06-27-2009, 04:52 PM
Injection Guide - by imported_Muto - 06-27-2009, 05:10 PM
Injection Guide - by Eighty Swords - 06-28-2009, 07:41 AM
Injection Guide - by Eighty Swords - 06-28-2009, 07:42 AM
Injection Guide - by imported_LudaKrishna - 06-28-2009, 08:22 AM
Injection Guide - by smoke - 06-28-2009, 08:23 AM
Injection Guide - by imported_Ryuuku - 06-28-2009, 03:04 PM
Injection Guide - by Eighty Swords - 06-28-2009, 05:44 PM
Injection Guide - by smoke - 06-28-2009, 06:31 PM
Injection Guide - by imported_LudaKrishna - 06-28-2009, 06:49 PM
Injection Guide - by Eighty Swords - 06-28-2009, 07:36 PM
Injection Guide - by imported_Ryuuku - 06-28-2009, 07:40 PM
Injection Guide - by Eighty Swords - 06-28-2009, 08:13 PM
Injection Guide - by imported_AptaR - 06-28-2009, 09:16 PM
Injection Guide - by Eighty Swords - 06-29-2009, 02:06 PM
Injection Guide - by imported_AptaR - 06-30-2009, 12:15 AM
Injection Guide - by smoke - 06-30-2009, 12:15 AM
Injection Guide - by imported_LudaKrishna - 06-30-2009, 06:36 PM
Injection Guide - by smoke - 07-02-2009, 12:34 AM
Injection Guide - by Eighty Swords - 07-02-2009, 03:00 AM
Injection Guide - by smoke - 07-02-2009, 04:19 AM
Injection Guide - by imported_LudaKrishna - 07-02-2009, 06:18 AM
Injection Guide - by imported_Papa Smurf - 07-03-2009, 04:35 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)