open.mp forum
[Pawn] Loops - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] Loops (/showthread.php?tid=612)



Loops - Cubie - 2019-05-28

Is there actually a way to check if a loop is finished?

I'm going to try to explain.



e.g loop:

PHP Code:
foreach (new Player)

{

? ??if(
example[playerid] == 4)

? ? {

? ? ? 
//Someting

? ? }

? ? return 
1;





e.g what I wonder:

PHP Code:
[Loop Finishes]

{

//Code





If anybody knows a fancy other trick that is fine too off course.

Thanks in advance.


RE: Loops - SyS - 2019-05-28

When a loop finishes the code outside its block gets executed.

Code:
for(.....) {

//code

}

//loop finished



RE: Loops - hual - 2019-05-28

pawn is synchronous so any code under your loop will be executed after the loop


RE: Loops - Cubie - 2019-05-28

Oh Sweet!

All I had to know Thanks guys!


RE: Loops - hual - 2019-05-28

Oh, and if you want to actually end a loop prematurely without exiting the function, use break, not return: https://wiki.sa-mp.com/wiki/Control_Structures#break


RE: Loops - Y_Less - 2019-05-28

Possibly the only good feature from Python is `for/else`. In pawn syntax:



PHP Code:
for (new 0!= 10; )

{

    if (
Something(i))

    {

        break;

    }

}

else

{

    
SomethingFailed();

}

// `break` jumps to here. 



The `else` block is only run if the loop exited without calling `break`, i.e. ended normally. I'm sure there's a way to fake or mimic it.


RE: Loops - Stanislav - 2019-05-28

(2019-05-28, 03:01 PM)Y_Less Wrote: Possibly the only good feature from Python is `for/else`. ?In pawn syntax:



PHP Code:
for (new 0!= 10; )

{

? ?if (
Something(i))

? ?{

? ? ? ?break;

? ?}

}

else

{

? ?
SomethingFailed();

}

// `break` jumps to here. 



The `else` block is only run if the loop exited without calling `break`, i.e. ended normally. ?I'm sure there's a way to fake or mimic it.



Im sorry if im deviating the topic but, why "the only good feature"?


RE: Loops - JustMichael - 2019-05-28

(2019-05-28, 09:00 PM)Stanislav Wrote:
(2019-05-28, 03:01 PM)Y_Less Wrote: Possibly the only good feature from Python is `for/else`. ?In pawn syntax:

PHP Code:
for (new 0!= 10; )
{
? ?if (
Something(i))
? ?{
? ? ? ?break;
? ?}
}
else
{
? ?
SomethingFailed();
}
// `break` jumps to here. 

The `else` block is only run if the loop exited without calling `break`, i.e. ended normally. ?I'm sure there's a way to fake or mimic it.

Im sorry if im deviating the topic but, why "the only good feature"?

He meant the only good feature that can translate to pawn and be useable (I think that's what he meant)


RE: Loops - Y_Less - 2019-05-28

I don't actually know Python well enough to say that's the only good feature, nor even what I meant which was more "good unique feature".