Loop in an array
#6

Quote:
Originally Posted by NealPeteros
Посмотреть сообщение
So uh, something like this?

PHP код:
for(new i=0i<10i++)
{
    if(
PlayerInfo[id][Inv][i] == 1)
    {
        
//code
    
}

Would this code check if the content of every [Inv] variable is equal to 1?
Not exactly, this will execute your code for every slot that is 1.

Create a variable before the loop to keep track if all of them are 1:

Код:
new bool:all_true = true;

for(new i=0; i<10; i++)
{
	if(PlayerInfo[id][Inv][i] != 1) // One of them is not 1, so set the variable to false
	{
		all_true = false;
		break; // Since we know that at least one is not true, we don't need to continue checking... Stop the loop
	}
}

if(all_true) // All indexes are 1
{
	// Code
}
Reply


Messages In This Thread
Loop in an array - by NealPeteros - 09.10.2018, 10:48
Re: Loop in an array - by Calisthenics - 09.10.2018, 11:00
Re: Loop in an array - by NealPeteros - 09.10.2018, 11:45
Re: Loop in an array - by NaS - 09.10.2018, 11:52
Re: Loop in an array - by NealPeteros - 09.10.2018, 12:07
Re: Loop in an array - by NaS - 09.10.2018, 12:11

Forum Jump:


Users browsing this thread: 1 Guest(s)