Do I need to include 'else' and/or 'endif'?

I realise this may be a generic php question, but as it’s related to WP I’m including it here.

If adding a simple conditional to my page.php template, do I need to include an ‘else’ (for other pages) and ‘endif’?

<?php
if (is_tree(39)) : get_template_part('templates/partial/menu-buy');
elseif (is_tree(117)) : get_template_part('templates/partial/menu-programs');
?>

Other than an ’empty condition’ (don’t know if that’s the right word) I can’t see a way to include an ‘else’ for other pages.

My limited knowledge suggests it’s probably good practice to finish with ‘endif’, but I’ve seen conditionals written with/without an ‘endif’ and hence wonder whether it’s necessary.

UPDATE: Thanks to those who’ve answered, I now realise there’s two different forms of syntax:
http://php.net/manual/en/control-structures.alternative-syntax.php
PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.

Solutions Collecting From Web of "Do I need to include 'else' and/or 'endif'?"

You just need an else block:

//templating syntax
if($condOne):
    //do stuff if $condOne is true
elseif($condTwo):
    //do stuff if $condOne is false and $condTwo is true
else:
    //do stuff if both $condOne and $condTwo are false
endif;

//braces syntax
if($condOne){
    //do stuff if $condOne is true
}elseif($condTwo){
    //do stuff if $condOne is false and $condTwo is true
else{
    //do stuff if both $condOne and $condTwo are false
}

Regarding “it’s probably good practice to finish with ‘endif'”, endif is only used when you are using the templating syntax:

if():
    //do stuff
endif;

the alternative is regular braces syntax:

if(){
    //do stuff
}

The former is preferable when you are outputting html by dropping out of php with a closing php tag, because an endif is easier to match up than a closing brace:

<?php if($someCondition):?>

   <h1>Hello <?=$userName?>, how are you today?</h1>
   <ul>
   <?php foreach($someArray as $key => $value):?>
       <li><?=$key?> : <?=$value?></li>
   <?php endforeach;?>
   </ul>

<?php endif;?>

VS:

<?php if($someCondition){?>

   <h1>Hello <?=$userName?>, how are you today?</h1>
   <ul>
   <?php foreach($someArray as $key => $value){?>
       <li><?=$key?> : <?=$value?></li>
   <?php }?>
   </ul>

<?php }?>

However when writting code that does not drop out of php mode, the latter is far more common and arguable easier to read:

$out=[];
if($someCondition){

    $out[$username]=[];

    foreach($someArray as $key => $value){

        $out[$username][] = $key . ' : ' . $value;

    }

}

Well @gulliver it’s kinda opinion based question. See we actually use endif to end the if conditional. If you are in a condition when a thing could change based on a condition then you have to use the else statement. Like below-

if('statement' == true ) {
    // do only when the statement is true
} else {
    // do only when the statement is false
}
// execute the other codes.

Notice in above case you can skip the else block if you do return. Cause PHP will not execute anything after return. So the code will be-

if('statement' == true ) {
    // do only when the statement is true        
    return 0;
    // Rest of the part will not be executed.
}
// This part will only execute when the statement is false.

Now the above code blocks can be written like below with different procedure using if():, else and endif

First code blocks

if('statement' == true ) :
    // do only when the statement is true
else :
    // do only when the statement is false
endif;
// execute the other codes.

Second Code Blocks

if('statement' == true ) :
    // do only when the statement is true        
    return 0;
    // Rest of the part will not be executed.
endif;
// This part will only execute when the statement is false.

Now decide yourself if you need to include else and/or endif. Ask any kinda question in you need to know further more.

endif went out of tyle years ago, should just avoid using it. Main reason that pops into my mind is lack of “block” detection by editors which make balancing ifs harder.

OTOH you should probably always have an else even if it is an empty one. The idea is that you show that you actually thought about what happens in the condition fails. Right now your snippet might have no output, is it intentional?

Best thing is probably use a linter that checks against the wordpress (or the wordpress.com VIP) coding standard. There is criticism against them, but having any coding standard is better then having none, and automatic tool that will test it helps you to actually follow it.