How to stop a for/while loop looping after it founds the first result?
#1

hey Guys, i know how to make a loop, but how can i stop the loop if it found the first result?

Код:
new strings[9][256];

for(new i=0;i<sizeof(strings);i++)
{
   if(!strlen(strings[i]))
   {
      format(strings[i],sizeof(strings[i],"blablabla %s",blah);
      TextDrawSetString(Request,strings[i]);
   }
}
//after it founds the first empty string, it should do the if action and then stop looping and going on here:
{
   Here would be the next thing to do //examplescript;
}



If i use return for that it just would end the function but there are more things to execute thats why i cant use it. Any Ideas?
Reply
#2

Is it break; ?
Reply
#3

cant you get it to do all the things?

anyways, heres a workaround

new strings[9][256];

for(new i=0;i<sizeof(strings);i++)
{
new empty=0;
if(empty != 1){
if(!strlen(strings[i]))
{
format(strings[i],sizeof(strings[i],"blablabla %s",blah);
TextDrawSetString(Request,strings[i]);
empty=1;
}
}
else
{
//your function here
}
}

}
Reply
#4

Thx.
Reply
#5

Using break is simpler.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)