08.02.2015, 23:48
pawn Код:
for (new i; i < 100; i++)
{
if (i == 50) break;
// Do something else here
}
Normally, the loop would run 100 times, right?
Since the for-loop is told to run from 0 to 99, it should run 100 times.
But in the code is some part where it checks the value of i, and if it's equal to 50, it executes "break".
So in fact, the loop will only run 51 times (from 0 to 50).
The code below the if-statement will only be executed 50 times (from 0 to 49), because when it's running the 51st run, i will be equal to 50, the loop is exited and the code below the if-statement won't be executed anymore.
The code you posted will run from 0 to 3, that's 4 times.
Unless either these array-indices hold a value of 0, then it will be exited:
PlayaInfo[playerid][0][0]
PlayaInfo[playerid][0][1]
PlayaInfo[playerid][0][2]
PlayaInfo[playerid][0][3]
If none of these holds 0, the loop will end by itself and variable "thebiz" will hold the value 3.
If PlayaInfo[playerid][0][1] holds the value 0, thebiz will hold 0, as i was 0 the last time before the loop was exited.
Basically:
- if PlayaInfo[playerid][0][0] holds 0, thebiz will hold it's previous value, whatever is was because "break" will prevent thebiz from taking over the value of i, as the loop is exited before the code is reached.
- if PlayaInfo[playerid][0][1] holds 0, thebiz will hold 0.
- if PlayaInfo[playerid][0][2] holds 0, thebiz will hold 1.
- if PlayaInfo[playerid][0][3] holds 0, thebiz will hold 2.
- if none of these hold 0, thebiz will hold 3.