Alternate Control Syntaxes

Started by chinmay.sahoo, 12-15-2015, 04:15:06

Previous topic - Next topic

chinmay.sahooTopic starter

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

Quoteif (expression):
statement1
statement2
..
endif;

Or:

Quoteif (expression):
statement1
statement2
..
elseif (expression2):
statement3
..
else:
statement4
..
endif;


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;

dark404

PHP offers an elective punctuation for a portion of its control structures; to be specific, if, while, for, foreach, and switch. For each situation, the essential type of the substitute grammar is to change the initial support to a colon (:) and the end support to endif;, endwhile;, endfor;, endforeach;, or endswitch;, separately.