Break two cikles - 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 two cikles (
/showthread.php?tid=555137)
Break two cikles -
Banditukas - 06.01.2015
Hi,
Код:
for(new i = 0; i < 50; i ++)
{
for(new w = 0; w < 25; w++)
{
// HOW TO BREAK THIS BOTH CIKLES IN ONE TIME?
}
}
Re: Break two cikles -
danish007 - 06.01.2015
Try This?
pawn Код:
for(new i = 0; i < 50; i ++)
{
for(new w = 0; w < 25; w++)
{
// HOW TO BREAK THIS BOTH CIKLES IN ONE TIME?
break;
}
break;
}
Re: Break two cikles -
PowerPC603 - 06.01.2015
There might still be some code in the outer loop, you don't wanna break the loop always.
Just adding "break" inside every loop would mean the outer loop would just run only once, when the inner loop finished execution.
Just add a variable as a flag and check it in every loop like this:
pawn Код:
new bool:BreakAllLoops = false;
for(new i = 0; i < 50; i ++)
{
for(new w = 0; w < 25; w++)
{
for (new x = 0; x < 100; x++)
{
// If some condition is true, set the variable to true
if (SomeCondition == true)
BreakAllLoops = true;
// Check if the variable is true
if (BreakAllLoops == true) break;
}
// Check if the variable is true
if (BreakAllLoops == true) break;
}
// Check if the variable is true
if (BreakAllLoops == true) break;
}
You can even break hundreds of loops at once using this.