mIRC Home    About    Download    Register    News    Help

Print Thread
#28061 04/06/03 05:53 AM
Joined: May 2003
Posts: 11
R
rw_grim Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: May 2003
Posts: 11
yes i know you can implement a for loop using a while loop. But we all know that script code doesn't execute as fast as c/c++/insert programming language here code thats compile for the instruction set of a processor. so not only would your code look a little bit cleaner, but your variabels would be set faster. Yeah i know it's not really justifiable, but it'd be nice..

#28062 04/06/03 06:35 AM
Joined: Dec 2002
Posts: 774
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Dec 2002
Posts: 774
And has been suggested before, next time, use the search before posting


Code:
//if ( khaled isgod ) echo yes | else echo no
#28063 05/06/03 02:15 AM
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Personally, I would have to say that a FOR command would be slower than WHILE. Just the way it would re-evaluate each parameter just incase any of them have changed... whereas WHILE loops only have to evaluate a single condition with as many parameters as you wish to specify. In most cases, this is just one.

mIRC is not C. Get use to the syntax and stop bit[b][/b]ching about conformity.

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
#28064 05/06/03 03:10 AM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
What do you mean it evaluates all the parameters?

for (initializer, conditional, incrementer) {
...
}

The initializer should only be evaluated the first time the loop is run. The conditional before each run, and the incrementer after each run. Maybe I'm missing something but how is that different than:

var %i = 0 ;the initializer
while (conditional) {
...
inc %i ;the incrementer
}

Here for example, just going on shortest code, which in a parsed language usually means fastest:

for (var %i = 0, %i <100, inc %i) echo -s %i

vs

var %i = 0
while (%i < 100) {
echo -s %i
inc %i
}

I really fail to see how the while loop should ever be faster, it is messier, and larger. I really don't know what you mean by "reevaluating each parameter" if you could be more descriptive, perhaps I can better understand what you mean.


Link Copied to Clipboard