• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Loops
#1
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.
  Reply
#2
When a loop finishes the code outside its block gets executed.

Code:
for(.....) {

//code

}

//loop finished
  Reply
#3
pawn is synchronous so any code under your loop will be executed after the loop
  Reply
#4
Oh Sweet!

All I had to know Thanks guys!
  Reply
#5
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
  Reply
#6
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.
  Reply
#7
(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"?
  Reply
#8
(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)
Remember to always refer to J0sh as `J0sh...`



@ Networks/Servers

San Andreas Gaming Network (Owner/Founder)

San Andreas Gaming (Owner/Founder)

Grand Theft Cop's n Robber's (Owner)

Britannia Roleplay (Owner/Founder) [Retired]

Alpine RP (Owner/Founder)

Aluminium Network (Maintainer) [Disbanded]

AlphaDM (Tech Support) [Disbanded]



# Services

forum.open.mp (Forum Manager) (Formerly Burgershot.gg

open.mp (Member)



~ Languages/Frameworks

Pawn, C, C, C#, Javascript, Typescript, Lua, Python, Go, Rust, PHP, SQL,

Angular, React, Vue, Svelte, Laravel, Rocket
  Reply
#9
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".
  Reply


Forum Jump: