SA-MP Forums Archive
Loop suspension - 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: Loop suspension (/showthread.php?tid=347646)



Loop suspension - Britas - 02.06.2012

Hi! I have one problem...

My code:
Код:
for(new i; i < 10; i++)
{
	if(!strcmp(BussinessCardInformation[bussinessId][i], "Nera", true))
	{
		SendClientFormatedMessage(playerid, LIMEGREEN, "* Radom laisvą vietą, prie %d staliuko.", i);
		break;
	}
}
I need to stop loop (break) and return loop (return). How?

Sorry for my bad english lang. i'm from lithuania


Re: Loop suspension - MadeMan - 02.06.2012

return does both. Use only return.


Re: Loop suspension - Niko_boy - 02.06.2012

use better : return or
continue

and when you break loop ,it just stops , you need some thing to restart it
https://sampwiki.blast.hk/wiki/Keywords:Statements#goto
this?


Re: Loop suspension - MP2 - 02.06.2012

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
return does both. Use only return.
Wrong.

break:
pawn Код:
print("before");
for(new i=0; i < MAX_PLAYERS; i++)
{
    print("inside");
    break;
}
print("after");
Outputs:
"before"
"inside"
"after"

return:
pawn Код:
print("before");
for(new i=0; i < MAX_PLAYERS; i++)
{
    print("inside");
    return 1;
}
print("after");
Outputs:
"before"
"inside"

Return stops the rest of the function/callback from being processed, break; just breaks from the loop.


Re: Loop suspension - MadeMan - 02.06.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
Wrong.
You're wrong. return DOES end the loop AND return from the function.


Re: Loop suspension - milanosie - 02.06.2012

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
You're wrong. return DOES end the loop AND return from the function.
I suggest you to try it out both?
I think MadeMan is right here, but I'm not 100% sure.


Re: Loop suspension - MP2 - 03.06.2012

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
You're wrong. return DOES end the loop AND return from the function.
You're wrong; again. I never said it didn't return from the function, I said it stops the rest of the function from being processed, which is true.


Re: Loop suspension - MadeMan - 03.06.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
You're wrong; again. I never said it didn't return from the function, I said it stops the rest of the function from being processed, which is true.
You quoted my post and said "Wrong". Wrong about what?

I would understand if you wanted to add something, but now I want to know what was wrong about what I said.


Re: Loop suspension - MP2 - 03.06.2012

You said 'return does both' - break and return. It does not break, because if it did break; it would process the code OUTSIDE the loop (after) but it doesn't, hence your wrongness.


Re: Loop suspension - milanosie - 03.06.2012

OMG THIS conversation is soo wrong.

Okay never mind, worst joke ever.