Home > Articles

This chapter is from the book

Employing Alternative Control Structure Syntax

For all the control structures we have looked at, there is an alternative form of syntax. It consists of replacing the opening brace ({) with a colon (:) and the closing brace with a new keyword, which will be endif, endswitch, endwhile, endfor, or endforeach, depending on which control structure is being used. No alternative syntax is available for do...while loops.

For example, the code

if ($totalqty == 0) {
  echo "You did not order anything on the previous page!<br />";
  exit;
}

could be converted to this alternative syntax using the keywords if and endif:

if ($totalqty == 0) :
  echo "You did not order anything on the previous page!<br />";
  exit;
endif;

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.