break in loop
#1

'break' in this loop doesn't seem to be doing what i want it to do.

pawn Код:
for(new i = 1; i < sizeof(HouseData); i++)
            {
                if(HouseData[i][Created] == 0) houseid = i;
                break;
            }
So obviously I have it start at 1, because I don't want a houseid to be 0, the first time it works fine and houseid ends up being 1, but after that, it keeps being 0, instead of 2, 3 etc.

If I don't use break, the houseid starts from 499 and descends (housedata has a limit of 500)
Reply
#2

That's because the break is unconditional and will always break at the first iteration. Use braces.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
That's because the break is unconditional and will always break at the first iteration. Use braces.
Unsure if I've done it right, because when the code executed it, it stopped executing and I couldn't input anymore commands (like froze the game, but I could still control the game..)

pawn Код:
for(new i = 1; i < sizeof(HouseData); i++)
            {
                while (HouseData[i][Created] == 0)
                {
                    houseid = i;
                }
            }
Reply
#4

pawn Код:
for(new i = 1; i < sizeof(HouseData); i++)
{
     if(HouseData[i][Created] == 0)
     {
               houseid = i;
               break;
     }
}
Reply
#5

Quote:
Originally Posted by Stanford
Посмотреть сообщение
pawn Код:
for(new i = 1; i < sizeof(HouseData); i++)
{
     if(HouseData[i][Created] == 0)
     {
               houseid = i;
               break;
     }
}
Worked fine, thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)