What is the diferents between these 2 thing? - 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: What is the diferents between these 2 thing? (
/showthread.php?tid=80406)
What is the diferents between these 2 thing? -
Andom - 04.06.2009
Hello,
What is the diferents between these 2 thing?
Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
}
and:
Код:
new idx;
while(idx < MAX_PLAYERS)
{
idx++;
}
And if there isn't any diferents, what is bether or faster?
Re: What is the diferents between these 2 thing? -
dice7 - 04.06.2009
Both are the same. But i preffer the for loop over while
Re: What is the diferents between these 2 thing? -
efeX - 04.06.2009
Quote:
Originally Posted by dice7
Both are the same. But i preffer the for loop over while
|
They are exactly the same thing except that while has no initializer or incremental step. while reduces to a special case of for.
Re: What is the diferents between these 2 thing? -
Luka P. - 04.06.2009
Same thing.
Re: What is the diferents between these 2 thing? -
Andom - 04.06.2009
Thank you guys! but which one do you prefer? i mean which is the fastest?
Re: What is the diferents between these 2 thing? -
samgreen - 04.06.2009
The code is functionally equivalent. The speed difference between these would be negligible, if you are seeking speed improvements I suggest you read some of the popular optimization threads. They can point you in the right direction.
Re: What is the diferents between these 2 thing? -
Lorrden - 04.06.2009
The "for" will make the script much more readable
Re: What is the diferents between these 2 thing? -
yom - 04.06.2009
Quote:
Originally Posted by ¤- Lorrden -¤
The "for" will make the script much more readable
|
It depend what you are doing. And yes i confirm there is no speed difference.