Break two cikles
#1

Hi,

Код:
for(new i  = 0; i < 50; i ++)
{
  for(new w = 0; w < 25; w++)
{
  // HOW TO BREAK THIS BOTH CIKLES IN ONE TIME?
}
}
Reply
#2

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;
}
Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)