SA-MP Forums Archive
Break cikle in foreach - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Break cikle in foreach (/showthread.php?tid=567781)



Break cikle in foreach - Banditukas - 16.03.2015

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 ?


Re: Break cikle in foreach - Stanford - 16.03.2015

I believe that the foreach will continue.


AW: Break cikle in foreach - Kaliber - 16.03.2015

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


Re: Break cikle in foreach - Banditukas - 16.03.2015

But it will break and foreach cikle too ?


Re: Break cikle in foreach - Stanford - 16.03.2015

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


Re: Break cikle in foreach - Vince - 16.03.2015

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.