switch() questions
#1

Hello,

I got a question about the switch() function.

Here is an example:

pawn Код:
switch(reason)
        {
            case 0:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Crashed)",playerid, pName);
            }
            case 1:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Leaving)",playerid, pName);
            }
            case 2:
            {
                format(string, sizeof(string),"[%d] %s has left the server. (Kicked/Banned)",playerid, pName);
            }
        }
Is there any reason to add a "else" inside this switch or something?
Any ideas?

Thanks
Reply
#2

Quote:
Originally Posted by Blt950
Посмотреть сообщение
Hello,

I got a question about the switch() function.

Here is an example:

pawn Код:
switch(reason)
        {
            case 0:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Crashed)",playerid, pName);
            }
            case 1:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Leaving)",playerid, pName);
            }
            case 2:
            {
                format(string, sizeof(string),"[%d] %s has left the server. (Kicked/Banned)",playerid, pName);
            }
        }
Is there any reason to add a "else" inside this switch or something?
Any ideas?

Thanks
pawn Код:
switch(reason)
        {
            case 0:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Crashed)",playerid, pName);
            }
            case 1:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Leaving)",playerid, pName);
            }
            case 2:
            {
                format(string, sizeof(string),"[%d] %s has left the server. (Kicked/Banned)",playerid, pName);
            }
            default:
            {
                //The else thingy
            }
        }
Reply
#3

Use default:
pawn Код:
case humm: format(humm);
default: //This is the else part.
Reply
#4

Ah, of course!

Thanks a lot
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)