Break cikle in foreach
#1

Hi,

Код:
foreach(new i : Player)
{
for(new n = 0; n < 5; n ++)
{
if( n == 3 )
{
   break;
}
}
}
It'is example script. It'is corrent and break cikle when n will be 3 and foreach cikle will be going next ?
Reply
#2

I believe that the foreach will continue.
Reply
#3

You must do sth like this:

Код:
new bool:stop;
foreach(new i : Player)
{
    for(new n = 0; n < 5; n ++)
    {
        if( n == 3 )
        {
           stop = true;
           break;
        }
    }
    if(stop) break;
}
Greekz
Reply
#4

But it will break and foreach cikle too ?
Reply
#5

According to your assumption, whenever a code sees 'break' it gets out of the shape or title and runs the next code..

though, I don't think that the foreach will break anyway.. I think that the For loop will alone
Reply
#6

A break statement only affects the innermost loop. Some languages have constructs to specify which loop should be broken, but Pawn does not have such construct.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)