SA-MP Forums Archive
Explanation. - 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)
+--- Thread: Explanation. (/showthread.php?tid=367594)



Explanation. - TaLhA XIV - 10.08.2012

PHP Code:
for(new i=0!=  MAX_PLAYERSi++) 
Hello,
As I am a learner so I needed anybody to explain this code for me,I wanted to learn this codes so please please can anyone explain this for me?
ThAnKs!


Re: Explanation. - phillip875 - 10.08.2012

This is an expression to count all the players on the server.

Also, it is:

pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
{
// action
}



Re: Explanation. - TaLhA XIV - 10.08.2012

Can you explain them to me like why do we need this:
PHP Code:
for 
why do we need this:
PHP Code:
(new 0
why do we need this:
PHP Code:
MAXPLAYERSi++ 
Please please.


Re: Explanation. - [MM]RoXoR[FS] - 10.08.2012

This is a for loop.
There are while and do while loop's as well.

What it does is, it first initialize i with 0 and check for condition(in your case i must not be equal to MAX_PLAYERS with is 500).

If condition is true, the code is executed.

Example
pawn Code:
for(new i=0;i<10;++i) printf("%d,"i);
In first eteration i = 0 which is less than 0 , so printf is executed and value of i is increased by 1.
This goes on till i is less than 10 .
In 10th eteration i will be 10. So loop stops

Code:
//result
0123456789
pawn Code:
for(i=0,j=10;j>15;++j,++i) {}
This loop is executed only 5 times as at 6th time j will be 15, which is not less than 15.


Re: Explanation. - TaLhA XIV - 10.08.2012

Ohh tHaNkS!