Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] Loops

 
  • 0 Vote(s) - 0 Average
Pawn Loops
Cubie
Offline

Burgershot Member
Posts: 8
Threads: 3
Joined: Apr 2019
Reputation: 0
Location: My House
#1
2019-05-28, 12:49 PM
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 i : 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.
SyS
Offline

Burgershot Member
Posts: 37
Threads: 5
Joined: Apr 2019
Reputation: 4
#2
2019-05-28, 02:12 PM
When a loop finishes the code outside its block gets executed.
Code:
for(.....) {
//code
}
//loop finished
hual
Offline

King

Posts: 106
Threads: 3
Joined: Feb 2019
Reputation: 7
Location: Bulgaria
#3
2019-05-28, 02:29 PM
pawn is synchronous so any code under your loop will be executed after the loop
Cubie
Offline

Burgershot Member
Posts: 8
Threads: 3
Joined: Apr 2019
Reputation: 0
Location: My House
#4
2019-05-28, 02:33 PM
Oh Sweet!
All I had to know Thanks guys!
hual
Offline

King

Posts: 106
Threads: 3
Joined: Feb 2019
Reputation: 7
Location: Bulgaria
#5
2019-05-28, 02:38 PM (This post was last modified: 2019-05-28, 02:38 PM by hual.)
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
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#6
2019-05-28, 03:01 PM
Possibly the only good feature from Python is `for/else`. In pawn syntax:

PHP Code:
for (new i = 0; i != 10; ++i)
{
    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.
Stanislav
Offline

Burgershot Member
Posts: 6
Threads: 0
Joined: Apr 2019
Reputation: 0
#7
2019-05-28, 09:00 PM
(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 i = 0; i != 10; ++i)
{
   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"?
JustMichael
Offline

Forum Manager

Posts: 189
Threads: 3
Joined: Feb 2019
Reputation: 17
Location: England
#8
2019-05-28, 09:02 PM (This post was last modified: 2019-05-28, 09:03 PM by JustMichael.)
(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 i = 0; i != 10; ++i)
{
   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)
Alpine RP (Owner/Founder)
Aluminium Network (Maintainer)
AlphaDM (Tech Support)

# Services
Burgershot.gg (Forum Manager)
open.mp (Member)

~ Languages/Frameworks
Pawn, C, C++, C#, Javascript, Typescript, Lua, Python, Go, Rust, PHP, SQL,
Angular, React, Vue, Svelte, Laravel, Rocket
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#9
2019-05-28, 11:28 PM
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".
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode