'for' loop/'if' statement bugging?
#1

Hey!

I was scripting and when I did the next;
pawn Код:
for(new i = 0; i < 1; i++)
    {
    printf("i = %d", i);
    }
The code would only print;
Код:
i = 0
Then I tried these two (Basically the same);
pawn Код:
for(new i = 0; i < 2; i++)
    {
    printf("i = %d", i);
    }
// and
for(new i = 0; i <= 1; i++)
    {
    printf("i = %d", i);
    }
The code (And crashdetect straight after it) printed;
Код:
i = 0
i = 1
Run time error 4: "Array index out of bounds"
Accessing element at index 2 past array upper bound 1
Then I got suspicious something had to be wrong as the first code would just loop with 0 and the second codes go to 2.
changed it like this;
pawn Код:
for(new i = -1; i < 2; i++)
    {
    printf("i = %d", i);
    if(i == 0 || i == 1)
        {
        }
    }
And it is still printing;
Код:
i = 0
i = 1
Run time error 4: "Array index out of bounds"
Accessing element at index 2 past array upper bound 1
The if statement is not bugging when it's on -1, as crashdetect isn't printing for accessing at negative index but it is bugging when 'i' gets to 2, as crashdetect is printing. How is this possible?!

Best regards,
Jesse

EDIT:
Even after changing the code to this;
pawn Код:
for(new i = 0; i < 2; i++)
    {
    if(i == 0 || i == 1)
        {
        if(i == 2) break;
        }
    }
Crashdetect is printing;
Код:
Run time error 4: "Array index out of bounds"
Accessing element at index 2 past array upper bound 1
Reply


Messages In This Thread
'for' loop/'if' statement bugging? - by jessejanssen - 17.06.2014, 17:27
Re: 'for' loop/'if' statement bugging? - by Konstantinos - 17.06.2014, 17:36
Re: 'for' loop/'if' statement bugging? - by Kimossab - 17.06.2014, 17:40
Re: 'for' loop/'if' statement bugging? - by jessejanssen - 17.06.2014, 17:49

Forum Jump:


Users browsing this thread: 1 Guest(s)