11.12.2018, 08:02
Only when i = 32 and i = 57 will the 'if' statement be triggered.
The statement will be called 100 times, but it is only 'true' when 'i' is equal to 32 or 57.
Eg.
Also, another trick when doing loops like this is to use 'sizeof'.
https://sampwiki.blast.hk/wiki/Keywords:Operators#sizeof
Your code would actually cause an 'Out of Bounds Error', because it iterates through 0 to 100, but an array with a size of 100 actually uses the indexes 0 to 99.
The statement will be called 100 times, but it is only 'true' when 'i' is equal to 32 or 57.
Eg.
PHP код:
if(Array[0] == 1) // false, skip
if(Array[1] == 1) // false, skip
if(Array[2] == 1) // false, skip
// ...
if(Array[31] == 1) // false, skip
if(Array[32] == 1) // true, continue!
{
Value[32] = 1;
}
if(Array[33] == 1) // false, skip
if(Array[34] == 1) // false, skip
// ...
if(Array[56] == 1) // false, skip
if(Array[57] == 1) // true, continue!
{
Value[57] = 1;
}
if(Array[58] == 1) // false, skip
PHP код:
for(new i = 0; i < sizeof(Array); i++)
Your code would actually cause an 'Out of Bounds Error', because it iterates through 0 to 100, but an array with a size of 100 actually uses the indexes 0 to 99.