ID:168522
![]() Oct 2 2005, 3:56 pm
|
|
What is to, what is it for, how does it work? It seems to be very useful, but I haven't a clue on how to use it. I would've searched the forum, but does anyone know how common the word to is? I'd get thousands of results.
|
Unknown Person wrote:
> var/x = rand(1, 10) I've never seen that way in use. I might try it sometime :) |
Unknown Person wrote:
> for(var/j = 1 to 10) You can also use step in that loop. for(var/i = 2 to 100 step 2) |
The following three lines of code are equivalent, and all output the same thing:
for(var/i = 0 to 100) world << i When you write "for(var/i = 1 to 100)," the "step 1" part is implied. The number after "step" tells BYOND how much to add to the variable per iteration. Therefore, the following two lines are equivalent, and both output the same thing: for(var/i = 0 to 100 step 2) Note that step also works with negative numbers: for(var/i = 100 to 0 step -1) |
For example, instead of a more complicated for loop:
We can just use the "to" operator to go by the numbers automatically.
They both end up doing the same thing. The first one is usually used for more complicated loops.
Mind that you can also do this to loop 10 times, but it is only useful to loop something 10 times without knowing what number it is at.
The second way I can think of right now is using it with switch(). You can check if a number is in a range of two numbers.
I might have missed some ways to use to, so there might be more.
It's odd that the BYOND Forums highlight "to" in the dm tags, but not the DM compiler.
~~> Dragon Lord