Alternate Control Syntaxes

Author Topic: Alternate Control Syntaxes  (Read 9307 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 158
  • Karma: 0
    • We Helpline
Alternate Control Syntaxes
« on: 12-15-2015, 04:15:06 »
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;

Or:

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


Offline harrywood

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 3
  • Posts: 160
  • Karma: 1
    • Mobile & web apps development
Re: Alternate Control Syntaxes
« Reply #1 on: 03-02-2019, 00:04:08 »
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.

Offline Lishmalinyjames

  • Trade Count: (0)
  • Hero Member
  • *****
  • Thank You 1
  • Posts: 784
  • Karma: 0
    • Oneplus Service Center in Chennai
Re: Alternate Control Syntaxes
« Reply #2 on: 03-26-2021, 02:25:07 »
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.

Offline Lishmalinyjames

  • Trade Count: (0)
  • Hero Member
  • *****
  • Thank You 1
  • Posts: 784
  • Karma: 0
    • Oneplus Service Center in Chennai
Re: Alternate Control Syntaxes
« Reply #3 on: 07-08-2021, 10:11:28 »
if(true):
  echo("Hello World!");
else:
  echo("Goodbye World!");
endif;

 

Related Topics

  Subject / Started by Replies Last post
0 Replies
2527 Views
Last post 11-24-2010, 12:36:03
by thosecars82
6 Replies
6922 Views
Last post 10-18-2019, 04:47:50
by lishmaliny
1 Replies
3140 Views
Last post 03-02-2019, 00:05:38
by harrywood
2 Replies
2620 Views
Last post 11-14-2012, 08:09:49
by dave-o99
0 Replies
4602 Views
Last post 01-30-2017, 03:09:44
by beingchinmay