SA-MP Forums Archive
For Loop or Foreach? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: For Loop or Foreach? (/showthread.php?tid=203129)



For Loop or Foreach? - anonymousx - 26.12.2010

What do you think is better? and Why?
I don't know which is better.


Re: For Loop or Foreach? - Souvlaki - 26.12.2010

If you mean whats the best way to loop through players, foreach no doubt.More efficient-faster.


Re: For Loop or Foreach? - XePloiT - 26.12.2010

foreach... because for(the loop) goes over all the players... and foreach goes through the online players


Re: For Loop or Foreach? - iggy1 - 26.12.2010

Foreach can be used for other loops too by making your own itterators. (i find it usefull for looping through teams or objects to)


Re: For Loop or Foreach? - scottyishere - 26.12.2010

I think this question has been answered a lot of times.

Yes, foreach is better because it only loops through certain IDs added by you with Iter_Add(...)

Iter_Add is not needed for player looping because it's done automatically.


Respuesta: For Loop or Foreach? - anonymousx - 02.01.2011

Thanks for your questions, I wasn't sure about this.