for - doesn't itter last array element
#1

I'm trying to do special loop, which iterates every array element. I've got this:

pawn Код:
new const Skins[] =
    {
        105, //0
        106, //1
        107, //2
        102, //3
        103, //4
        104, //5
        114, //6
        115, //7
        116, //8
        108, //9
        109, //10
        110, //11
        121, //12
        122, //13
        124, //14
        126, //15
        113  //16
    };

    for(new skin = Skins[0], skin_index = 1; skin_index < sizeof(Skins); skin = Skins[skin_index++])
        printf("%d", skin);

    print("Text"); //Debug
But doesn't iterate last array element:
Quote:
Originally Posted by console
[19:43:20] 105
[19:43:20] 106
[19:43:20] 107
[19:43:20] 102
[19:43:20] 103
[19:43:20] 104
[19:43:20] 114
[19:43:20] 115
[19:43:20] 116
[19:43:20] 108
[19:43:20] 109
[19:43:20] 110
[19:43:20] 121
[19:43:20] 122
[19:43:20] 124
[19:43:20] 126 //there's no 113 :/
[19:43:20] Text
Reply
#2

try this: skin_index <= sizeof(Skins)

There might be some delay in the loop, so that it is ended when skin_index is too high (skin = Skins[skin_index++]) without running printf("%d", skin); again.
Reply
#3

I tried it, but debug string doesn't print :C
Reply
#4

I doubt it, but maybe setting the size of the array may help.

new const Skins[17] =
Reply
#5

Still doesn't work
Reply
#6

This post -> Delete
Reply
#7

For me it works with the <=

for(new skin = Skins[0], skin_index = 1; skin_index <= sizeof(Skins); skin = Skins[skin_index++])

EDIT: Oops, it does not work, forgot the debug message
This is not as comfortable as yours, but at least works:

for(new skin_index = 1; skin_index < sizeof(Skins); skin_index ++ )
printf("%d", Skins[skin_index]);
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)