[Help] Control structures
#8

Quote:
Originally Posted by Finn
This loop will stop when i is 45, so it means it stops at player id 45, which is 46th player, because 45 ids + id 0 = 46.

pawn Код:
for (new i=0; i<MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        if(i == 45) break;
    }
}

Break stops just the loop, return stops the whole function. In this example "YAY" will not be printed, but if you used break instead of return, "YAY" would be printed.

pawn Код:
main()
{
    for(new i; i < 20; i++)
    {
        printf("i = %d", i);
        if(i == 10) return 1;
    }
    print("YAY");
    return 1;
}
Ok, I understood, thanks dude.

Quote:
Originally Posted by ******63
First is because it has 'j++' that is same as 'j += 1' so every time it loop add 1 to variable 'j' - if that was your question
You're actually wrong, cause the j++ appears after the printf. But at each loop j is set to 1 and then increased ("j<3; j++") to 1 so j would be 1 then 2 then 1 then 2 then 1 for an infinite loop! (assuming new has the same effect than static)
Reply


Messages In This Thread
[Help] Control structures - by Coicatak - 11.03.2009, 19:41
Re: [Help] What's the difference between new and static - by MenaceX^ - 11.03.2009, 19:44
Re: [Help] What's the difference between new and static - by Coicatak - 11.03.2009, 19:49
Re: [Help] Control structures - by Marcel - 11.03.2009, 20:50
Re: [Help] Control structures - by Coicatak - 12.03.2009, 13:36
Re: [Help] Control structures - by Google63 - 12.03.2009, 13:52
Re: [Help] Control structures - by Finn - 12.03.2009, 13:56
Re: [Help] Control structures - by Coicatak - 12.03.2009, 15:09

Forum Jump:


Users browsing this thread: 1 Guest(s)