Switch
#4

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
Switch-case? It's one of the simplest things around pawn.
It can replace if conditionals and sometimes save up some space aswell.
Example:
pawn Код:
if(a == b)
{
     //Do something
}
else if(a == c)
{
    //Do something
}
else if(a == d || a == e || a == f)
{
    //Do something
}
That is equal to:
pawn Код:
switch(a)
{
    case b:
    {
        //Do something
    }
    case c:
    {
        //Do something
    }
    case d, e, f:
    {
        //Do something
    }
}
It's quite useful if you're checking a single varible for various values.
You forget about default (else). However, this example(s) is/are the best:
https://sampwiki.blast.hk/wiki/Control_Structures#switch
You got everything explained there.
Reply


Messages In This Thread
Switch - by Syntax - 09.04.2013, 11:42
Re: Switch - by IstuntmanI - 09.04.2013, 11:45
Re: Switch - by [XST]O_x - 09.04.2013, 11:46
Re: Switch - by Riddick94 - 09.04.2013, 12:13
Re: Switch - by Syntax - 09.04.2013, 16:19
Re: Switch - by Scenario - 09.04.2013, 16:22
Re: Switch - by Riddick94 - 09.04.2013, 16:22
Re: Switch - by Syntax - 09.04.2013, 16:25
Re: Switch - by RicaNiel - 09.04.2013, 16:27
Re: Switch - by Scenario - 09.04.2013, 17:19
Re: Switch - by Isolated - 09.04.2013, 17:21
Re: Switch - by Syntax - 09.04.2013, 19:17
Re: Switch - by Syntax - 10.04.2013, 09:13
Re: Switch - by Scenario - 10.04.2013, 14:52
Re: Switch - by SchurmanCQC - 10.04.2013, 14:56
Re: Switch - by Syntax - 10.04.2013, 15:06

Forum Jump:


Users browsing this thread: 1 Guest(s)