How to stop a loop ?
#1

So here's an example:

pawn Код:
for(new i = 0; i < 5; i++)
{
  if(something[i] == 0)
  {
    dosomething;
  }
  else
  {
    error;
  }
}
So i want to stop the loop when the array equals to zero, and if the loop reaches it end and didn't find an array equaled to zero, then display the error message...

I can't seem to stop it, so please help, thank you.
Reply
#2

BUMP. I really need this quick...
Reply
#3

Just use break;
Код:
for(new i = 0; i < 5; i++)
{
  if(something[i] == 0)
  {
    dosomething;
    break;
  }
  else
  {
    error;
  }
}
Reply
#4

Quote:
Originally Posted by Jefff
Just use break;
Код:
for(new i = 0; i < 5; i++)
{
  if(something[i] == 0)
  {
    dosomething;
    break;
  }
  else
  {
    error;
  }
}
I tryed that, and i tryed using return 1; , both of them don't work and the loop executes the else and continues on..
Reply
#5

try continue;
Reply
#6

Doesn't work either.
Reply
#7

break; stops the loop, continue; stops the literation and continues from the start of the loop. You're doing something wrong
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)