for() vs foreach()
#10

Foreach is faster. All of you guys are WRONG. Foreach doesn't loop through all players and check if they are online.

When a player connects it adds their id into an Iteration. Foreach loops through the iteration of connected id's.

Example:
Code:
id 0 connected
id 5 connected
id 99 connected
It wont loop through all 100 players checking if 0,5,99 are connected. Since it is in the interation, it will only pass through the id's: 0, 5, and 99. Nothing else.

If you have two players in the server with id 40 and 60, it wont loop through numbers 1-60, it will only output id 40, and 60.
Reply


Messages In This Thread
for() vs foreach() - by The Scripter - 20.08.2010, 22:04
Re: for() vs foreach() - by Vince - 20.08.2010, 22:29
Re: for() vs foreach() - by CaHbKo - 20.08.2010, 22:31
Re: for() vs foreach() - by Carlton - 20.08.2010, 22:56
Re: for() vs foreach() - by Nero_3D - 20.08.2010, 23:24
Re: for() vs foreach() - by The Scripter - 20.08.2010, 23:32
Re: for() vs foreach() - by [L3th4l] - 20.08.2010, 23:35
Re: for() vs foreach() - by Simon - 20.08.2010, 23:51
Re: for() vs foreach() - by The Scripter - 20.08.2010, 23:58
Re: for() vs foreach() - by lolumadd - 21.08.2010, 00:04

Forum Jump:


Users browsing this thread: 1 Guest(s)