different client looping?
so i've noticed that alot of code just loops through using a simple for loop
PHP Code:
PHP Code:
Also, does it make any difference in execution speed if I use the loop in reverse? PHP Code:
|
Re: different client looping?
It's the same (just syntax simplification). At compile time
PHP Code:
PHP Code:
|
Re: different client looping?
I wouldn't call it shorter.
It has one extra line! |
Re: different client looping?
Quote:
PHP Code:
|
Re: different client looping?
There could be a point where simplifying ends up making things less readable. Everyone with a basic knowledge of for loops can make sense of "declare a variable, check if value is within bounds, increment", but some newer users might take a bit more time to understand "declare a variable, check the prefix incremented value (what does that even mean?), why is there nothing in the third spot".
For the while-loop in the first post, it's a case of scope; client will continue to be available outside of the loop. Personal opinion, but it just seems cleaner to have a variable declared in the scope of the loop rather than worry about it if you use multiple loops in one function (you'd have to declare a new variable or reinitialize an existing one for each). Regardless, we could use any of those variations; it's just different. |
Re: different client looping?
I use for loops for clients because I'm used to them and know they work. I never bothered myself with finding a new way to do these.
Anyways, I wonder how Sourcepawn handels preincrement and postincrement. |
Re: different client looping?
I seen people who loop through clients like so
for(new i = MaxClients+1; i>0; i--) Which is weird, but essentially covers all players just like incremental. |
Re: different client looping?
Quote:
plus, is there more performance speed to pre or post inc/dec-rement? |
Re: different client looping?
Quote:
And by the way, it's probably the best to do: Code:
First case just loads a variable and generates "jump if 0" instruction, which is better than second case because it loads the first variable from the stack, the second one from data and then generates "jump if greater" instruction. Anyway, we are talking here about micro optimizations. |
Re: different client looping?
Quote:
|
| All times are GMT -4. The time now is 22:34. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.