Raised This Month: $ Target: $400
 0% 

Please explain For Loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
VarmaRitik
Senior Member
Join Date: Jul 2014
Location: India
Old 02-28-2015 , 00:12   Please explain For Loop
Reply With Quote #1

Hello,
Can someone please explain me "For" Loop..?
Here is an example I got.
Code:
new iPlayers[32], iNum, Player 
get_players(iPlayers, iNum, "b")
for( new i; i<iNum; i++ )
{ 
    Player = iPlayers[i] 
    // ...
}
What do these means..? someone please explain me.

Thank You.
VarmaRitik is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 02-28-2015 , 00:24   Re: Please explain For Loop
Reply With Quote #2

PHP Code:
for(
   
initialization(s)
;
   
condition(s)
;
   
code to execute)
{


It initializes one time "initialization(s)".
While the condition is TRUE, it executes the code between { } and then "code to execute".

Example.

PHP Code:
for (new 01player[32] = "Hattrick";  != 2j++)
{
  
server_print("1");

This initializes 'new' variables, executes 'server_print' and 'j++' one time.
Why one time? Because after 'server_print' is executed, 'j' gets +1 and it will be 2. When the condition is FALSE, it stops.

You can stop the loop with 'break', skip with 'continue' or break the loop and end the function() with 'return (?value?);'.
__________________

Last edited by claudiuhks; 02-28-2015 at 00:28.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-28-2015 , 04:33   Re: Please explain For Loop
Reply With Quote #3

A for loop is an extremely common programming construct and you can find a bunch of information about them online. For loops in Pawn are very C-like.
__________________

Last edited by fysiks; 02-28-2015 at 04:33.
fysiks is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 02-28-2015 , 04:42   Re: Please explain For Loop
Reply With Quote #4

You really need to learn this stuff on your own. There are tons of tutorials available on pawn and C. Members of this forum are not here to spoon feed you. Buy veteran coder a cup of coffee and he would gladly help you understand pawn coding, but don't expect anyone to spoon feed you without any incentive.

All these threads are just asking for that, when you don't even care to search.

https://forums.alliedmods.net/showthread.php?t=258986
https://forums.alliedmods.net/showthread.php?t=258992
https://forums.alliedmods.net/showthread.php?t=258991
https://forums.alliedmods.net/showthread.php?t=257591
Spirit_12 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:07.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode