foreach strange problem
#1

Hi guys, I am doing a vehicle system and I've found a problem.
When the foreach loop starts it only does executes once and then stops, but I need it to foreach 50 times (MAX_VEH).

My question is: why it stops after the first execution?

Here's the code:
pawn Code:
for(new i = 1; i != MAX_VEH; i++)
{
    Iter_Add(Vehicles, i);
}

foreach(Vehicles, v)
{
    format(qStr, sizeof(qStr), "SELECT * FROM Veicoli WHERE ID = %d", v);
    REZ = db_query(vDatabase, qStr);
    if(db_num_rows(REZ) == 0)
    {
        Iter_Remove(Vehicles, v);
        printf("[WARNING]: Iter_Remove: %d", v);
        db_free_result(REZ);
        continue;
    }
    // Rest of the code...
}
Reply
#2

Ok, I've tested again and if I remove the function "Iter_Remove" from the code the loop works fine.
But I need that function. How can I solve this problem? Thank you!
Reply
#3

Oh thanks, I get it now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)