Loop question
#1

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
Reply
#2

It is called a nested loop. It is quite common.
Reply
#3

Is it alright to make it?
Reply
#4

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++)
Reply
#5

Sounds quite easy, thank yu!
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: