Coding & Programming > Programming Forum

Alternate Control Syntaxes

(1/1)

chinmay.sahoo:
PHP offers another way to start and end the bodies of the if, switch, for, and while constructs. It amounts to replacing the initial brace of the enclosed block with a colon and the closing brace with a special ending statement for that construct (endif, endswitch, endfor, and endwhile). For example, the if syntax becomes


--- Quote ---if (expression):
statement1
statement2
..
endif;
--- End quote ---

Or:


--- Quote ---if (expression):
statement1
statement2
..
elseif (expression2):
statement3
..
else:
statement4
..
endif;
--- End quote ---

harrywood:
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.

Lishmalinyjames:
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.

Lishmalinyjames:
if(true):
  echo("Hello World!");
else:
  echo("Goodbye World!");
endif;

Navigation

[0] Message Index

Go to full version