Loop suspension
#1

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
Reply
#2

return does both. Use only return.
Reply
#3

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?
Reply
#4

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

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

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

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

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

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

OMG THIS conversation is soo wrong.

Okay never mind, worst joke ever.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)