How to stop a for/while loop looping after it founds the first result? - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to stop a for/while loop looping after it founds the first result? (
/showthread.php?tid=141749)
How to stop a for/while loop looping after it founds the first result? -
DJ-CJ89 - 15.04.2010
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?
Re: How to stop a for/while loop looping after it founds the first result? -
DJ-CJ89 - 15.04.2010
Is it break;
![Huh?](images/smilies/confused.gif)
?
Re: How to stop a for/while loop looping after it founds the first result? -
adsy - 15.04.2010
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
}
}
}
Re: How to stop a for/while loop looping after it founds the first result? -
DJ-CJ89 - 15.04.2010
Thx.
Re: How to stop a for/while loop looping after it founds the first result? -
MenaceX^ - 15.04.2010
Using break is simpler.