[Tutorial] Beautiful, Readable Code (Indentation, Whitespace, Comments)
#7

Quote:
Originally Posted by AIped
Посмотреть сообщение
Hmm..so for example if i need to check many things i do something like this;

pawn Код:
if(IsPlayerInRangeOfPoint(blablabla))
{
    if(GetPlayerState(playerid)== blabllablala)
    {
        if(GetPlayerWeaponSkill bla bla blaaah
        {
             if(blaaaaaaa )
             {
             (and so on)
             }
             else
             {
             blablabla
             }
        }
    }
}
Is it bad to have so many if's ? i try to narrow it down but mostly im not sure what is best
There is no problem with having several if statements, but sometimes you can cut down on them by using logical operators (&&, ||) or other means of organization (such as cases). It depends on the specific scenario and whether or not you need unique results in each case.

As for your indentation, you are almost there! You properly indented all nested items except the end results. Here is the correct indentation:

pawn Код:
if(IsPlayerInRangeOfPoint(blablabla))
{
    if(GetPlayerState(playerid)== blabllablala)
    {
        if(GetPlayerWeaponSkill bla bla blaaah
        {
             if(blaaaaaaa )
             {
                (and so on)
             }
             else
             {
                blablabla
             }
        }
    }
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)