ID:149767
Feb 20 2002, 1:16 pm
|
|
Im suppose to be studying it but i cannot find it in my book so could one of you explain to me what it does
|
In response to Nova2000
|
|
Nova2000 wrote:
> for(myvar=0, myvar<8, myvar++) { The only trouble with Nova's example is that there are no brackets or parenthesis for the statement that is executed in the loop, as you would see in other languages like C or PHP. The correct format for Nova's example would be (including variable declaration): var/myvar |
Vejita99 wrote:
Im suppose to be studying it but i cannot find it in my book so could one of you explain to me what it does If this is something you're supposed to study, I'd venture a guess you're talking about other languages, not DM, right? For loops vary in different languages. In DM they take a few forms: for(x in list) In C-style languages, they look like this: for(x=5;x>0;--x) { In BASIC and Visual Basic: for x=5 to 1 step -1 Lummox JR |
Vejita99 wrote:
Im suppose to be studying it but i cannot find it in my book so could one of you explain to me what it does The Reference explains this quite well: http://www.byond.com/docs/ref/info.html#/proc/for/loop and http://www.byond.com/docs/ref/info.html#/proc/for/list |
In response to digitalmouse
|
|
Heh, Ooops, guesss I've programed in PHP too long. :)
|
Sure. Here's what for is:
for(Init, Test, Inc) {
Statement
}
For basically does what's in it, can keeps checking to see if Test is met, if not it does an Inc (Increase)
I assume you know what arguments are? Init is what you want you variable to start at, Test is a test to see if you want to stop the loop, and Inc is the increasment value.
Say I wanted to print out several a messages to the user at once, as long a variable was lower than 8. So I'd:
1) It would set myvar to zero.
2) It would then to the script inside.
3) Check to see if myvar<8. If it isn't, then it quits.
4) Else, add one to myvar, Repeat!
That help?