cvs: /phpdoc/language control-structures.sgml

From: Date: Sun, 14 Nov 1999 23:16:30 +0000
Subject: cvs: /phpdoc/language control-structures.sgml
Groups: php.dev 
Request: Send a blank email to php-dev+get-12532@lists.php.net to get a copy of this message
cslawi Sun Nov 14 18:16:30 1999 EDT Modified files: /phpdoc/language control-structures.sgml Log: Updated the Alternative syntax section to include the other structures which support the syntax; added note to switch section mentioning that it supports it; added some references to the individual examples. Index: phpdoc/language/control-structures.sgml diff -u phpdoc/language/control-structures.sgml:1.5 phpdoc/language/control-structures.sgml:1.6 --- phpdoc/language/control-structures.sgml:1.5 Wed Oct 20 18:52:31 1999 +++ phpdoc/language/control-structures.sgml Sun Nov 14 18:16:29 1999 @@ -139,24 +139,26 @@ <literal>elseif</literal> expression evaluated to <literal>TRUE</literal>.</simpara></sect1> <sect1 id="control-structures.alternative-syntax"> - <title>Alternative syntax for <literal>if</literal> structures: <literal>if(): ... endif;</literal></title> + <title>Alternative syntax for control structures</title> - <para> - PHP offers a different way to group statements within an - <literal>if</literal> statement. This is most commonly used when - you nest HTML blocks inside <literal>if</literal> statements, but - can be used anywhere. Instead of using curly braces, <literal>if - (<replaceable>expr</replaceable>)</literal> should be followed - by a colon, the list of one or more statements, and end with - <literal>endif;</literal>. Consider the following example: - + <para> + PHP offers an alternative syntax for some of its control + structures; namely, <literal>if</literal>, + <literal>while</literal>, <literal>for</literal>, and + <literal>switch</literal>. In each case, the basic form of the + alternate syntax is to change the opening brace to a colon (:) and + the closing brace to <literal>endif;</literal>, + <literal>endwhile;</literal>, <literal>endfor;</literal>, or + <literal>endswitch;</literal>, respectively. + <informalexample> <programlisting> &lt;?php if ($a==5): ?&gt; - A = 5 + A is equal to 5 &lt;?php endif; ?&gt; </programlisting> - </informalexample></para> + </informalexample> + </para> <simpara> In the above example, the HTML block "A = 5" is nested within an @@ -181,7 +183,16 @@ print "a is neither 5 nor 6"; endif; </programlisting> - </informalexample></para></sect1> + </informalexample> + </para> + + <para> + See also <link linkend="control-structures.while">while</link>, + <link linkend="control-structures.for">for</link>, and <link + linkend="control-structures.if">if</link> for further examples. + </para> + + </sect1> <sect1 id="control-structures.while"> <title><literal>while</literal></title> @@ -560,13 +571,41 @@ print "i is not equal to 0, 1 or 2"; } </programlisting> - </informalexample></para> + </informalexample> + </para> <para> The <literal>case</literal> expression may be any expression that evaluates to a scalar type, that is, integer or floating-point numbers and strings. Arrays or objects are meaningless in that - context.</para></sect1> + context. + </para> + + <para> + The alternative syntax for control structures is supported with + switches. For more information, see <link + linkend="control-structures.alternative-syntax">Alternative + syntax for control structures</link> . + + <informalexample> + <programlisting> +switch ($i): + case 0: + print "i equals 0"; + break; + case 1: + print "i equals 1"; + break; + case 2: + print "i equals 2"; + break; + default: + print "i is not equal to 0, 1 or 2"; + endswitch; + </programlisting> + </informalexample></para> + + </sect1> <sect1 id="function.require"> <title><literal>require</literal></title>

« previous php.dev (#12532) next »