Braces
#1

Are braces needed in all if statements and or will it cause problems to not have them?

hears an example where i don't use braces:

pawn Код:
if(PlayerToPlayer(i, CurrentPresident(), 50))
                    SetPlayerWantedLevel(i, 1);
                else if(PlayerToPlayer(i, CurrentPresident(), 40))
                    SetPlayerWantedLevel(i, 2);
                else if(PlayerToPlayer(i, CurrentPresident(), 30))
                    SetPlayerWantedLevel(i, 3);
                else if(PlayerToPlayer(i, CurrentPresident(), 20))
                    SetPlayerWantedLevel(i, 4);
                else if(PlayerToPlayer(i, CurrentPresident(), 10))
                    SetPlayerWantedLevel(i, 5);
                else
                    SetPlayerWantedLevel(i, 0);
Reply
#2

I don't use braces, and they work fine for me.
Reply
#3

This should work fine though.
Reply
#4

The braces are used when there are more than 1 function.

If you use 1 function , you can use or not Braces ( same thing )

e.g.
pawn Код:
if(PlayerLevel[playerid] > 1) return SendClientMessage(playerid,COLOR_WHITE,"ETC");
it's equal with:
pawn Код:
if(PlayerLevel[playerid] > 1) { return SendClientMessage(playerid,COLOR_WHITE,"ETC"); }
************************************************** ***************************

If you use 2 functions ore more , you must use the Braces, or you'll get errors.
e.g.
pawn Код:
if(PlayerLevel[playerid] > 1)
{
  Kick(playerid);
  return SendClientMessage(playerid,COLOR_WHITE,"ETC");
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)