Home > Articles

  • Print
  • + Share This
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;
  • + Share This
  • 🔖 Save To Your Account