16.09.2017, 21:51
Quote:
Code that is using foreach = Optimized, Code that is using for(new i; i < MAX_PLAYERS; i++) is unoptimized
|
Quote:
MAX_PLAYERS is just a macro definition of an int..
Foreach is the definition of a macro defined for() loop (I guess, never looked into its source) It's the same thing, for() while() etc etc, it's still PAWN, it's still a loop. No matter what people use, it's the same thing over and over, but how you use it is what's important. https://sampwiki.blast.hk/wiki/Control_Structures#Loops |
It uses a loop, yes, but a dynamic loop, saving you processing time.
When you use frequently a certain loop, like in a timer with an interval of 1000 milliseconds, you'd want it to be as fast as possible, foreach will sure ensure it.
foreach uses the y_iterate approach, which is also a child library of YSI.
Loops are useful, but they're better when they're short.