[Doubt] Loop's
#3

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.
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 
Also, another trick when doing loops like this is to use 'sizeof'.
PHP код:
for(new 0sizeof(Array); i++) 
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.
Reply


Messages In This Thread
[Doubt] Loop's - by ApolloScripter - 10.12.2018, 19:24
Re: [Doubt] Loop's - by ItsRobinson - 10.12.2018, 19:36
Re: [Doubt] Loop's - by Threshold - 11.12.2018, 08:02

Forum Jump:


Users browsing this thread: 1 Guest(s)