Else or Else if?
#1

Hello, i've have an question here
Код:
	else if(rand == 0)
there else or else if?
Код:
    new Humans, Zombies, rand = random(2);
	if(rand == 0) 
	{
	    foreach(Player, i)
	    {
	        if(Humans == Zombies)
	        {
				HumanSetup2(i);
	            Humans ++;
	        }
	        else
	        {
	            ZombieSetup2(playerid);
	            Zombies ++;
	        }
	    }
	}
	else if(rand == 0) // Here else or else if?
	{
	    foreach(Player, i)
	    {
	        if(Humans == Zombies)
	        {
	            ZombieSetup2(i);
	            Zombies ++;
	        }
	        else
	        {
	            HumanSetup2(i);
	            Humans ++;
	        }
	    }
	}
Reply
#2

This makes no sense, as you already covered it with if statement. If you want to compare against 1, normal else will suffice. Also !rand is equal rand == 0
Reply
#3

Also just "else"?
Reply
#4

Like this.....

r = random(2);
if(r == 0) { }
else { } // r = 1

use elseif when.....

r = random(3);
if(r == 0) {}
else if(r == 1) {}
else {} // r = 2
Reply
#5

pawn Код:
new Humans, Zombies, rand = random(2);
foreach(Player, i)
{
    if(rand && Humans == Zombies)
    {
        ZombieSetup2(i);
        Zombies ++;
    }
    else
    {
        HumanSetup2(i);
        Humans ++;
    }
}
Reply
#6

Thanks! And that is right, or?

Код:
stock Half()
{
	new Humans;
	foreach(Player, i)
	{
	    if(Humans < 3)
	    {
	        HumanSetup(i);
	        Humans ++;
	    }
	    else
	    {
	        ZombieSetup2(i);
	        Humans = 0;
	    }
	}
	return 1;
}
Reply
#7

If its task is to create 2 humans per zombie, then looks fine to me.
Reply
#8

https://sampwiki.blast.hk/wiki/Control_Structures#else
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)