I was wondering if there is any performance difference between the following 2 syntax of if-statement(similarly for other loops – while, for, foreach etc) :
if(..) {...}
else {...}
AND
if(..) : ...
else : ...
endif;
Any advantages of using one over the other?
You normally use the alternative syntax (
if (condition):endif;) in views (templates) as it’s easier to read amongst HTML. For example:Is easier to read than:
Especially as you add more control structures such as
if,foretc. If you use curly braces in HTML, it becomes harder to distinguish which closing curly brace belongs to which opening curly brace, whereas using the alternative syntax you know withendifyou’re looking for an openingif:statement.Hope that helps.