SA-MP Forums Archive
Loop question - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Loop question (/showthread.php?tid=237556)



Loop question - admantis - 09.03.2011

I have a question, is it recommended or something inusual if you run a loop inside a loop?

i.e:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++) // foreach(Player, i)
    {
        if (av[i] == 5)
        {
            for(new i = 0; i < MAX_PLAYERS; i++) // foreach(Player, i)
thanks


Re: Loop question - mprofitt - 09.03.2011

It is called a nested loop. It is quite common.


Re: Loop question - admantis - 09.03.2011

Is it alright to make it?


Re: Loop question - Serbish - 09.03.2011

Quote:
Originally Posted by admantis
Посмотреть сообщение
I have a question, is it recommended or something inusual if you run a loop inside a loop?

i.e:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++) // foreach(Player, i)
    {
        if (av[i] == 5)
        {
            for(new i = 0; i < MAX_PLAYERS; i++) // foreach(Player, i)
thanks
You have to create another variable for the second loop.

Example:

pawn Код:
for(new i_2 = 0; i_2 < MAX_PLAYERS; i_2++)



Re: Loop question - admantis - 09.03.2011

Sounds quite easy, thank yu!


Re: Loop question - mprofitt - 09.03.2011

Quote:
Originally Posted by admantis
Посмотреть сообщение
Is it alright to make it?
Yeah, I have done 3 and 4 nested loops.

Serbish is correct that you will need a new variable.