Date: 07/31/99
- Next message: Jim Winstead: "[PHP-DEV] cvs: /phpdoc/functions dbase.sgml"
- Previous message: Jim Winstead: "[PHP-DEV] cvs: /phpdoc/functions strings.sgml"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
jim Sat Jul 31 20:46:16 1999 EDT
Modified files:
/phpdoc/language control-structures.sgml
Log:
Be more explicit in showing how multiple 'case' statements can be grouped.
Remove in-line numbers from the informal examples.
Index: phpdoc/language/control-structures.sgml
diff -u phpdoc/language/control-structures.sgml:1.3 phpdoc/language/control-structures.sgml:1.4
--- phpdoc/language/control-structures.sgml:1.3 Tue Jul 13 18:21:49 1999
+++ phpdoc/language/control-structures.sgml Sat Jul 31 20:46:16 1999
@@ -465,8 +465,6 @@
<informalexample>
<programlisting>
- /* example 1 */
-
if ($i == 0) {
print "i equals 0";
}
@@ -477,8 +475,6 @@
print "i equals 2";
}
- /* example 2 */
-
switch ($i) {
case 0:
print "i equals 0";
@@ -495,22 +491,20 @@
<para>
It is important to understand how the <literal>switch</literal>
- statement is executed in order to avoid messups. The
+ statement is executed in order to avoid mistakes. The
<literal>switch</literal> statement executes line by line (actually,
statement by statement). In the beginning, no code is executed.
- Only when a <literal>case</literal> statement is found with a value that matches the
- value of the <literal>switch</literal> expression, PHP begins to
- execute the statements. PHP continues to execute the statements
- until the end of the <literal>switch</literal> block, or the first
- time it sees a <literal>break</literal> statement. If you don't
- write a <literal>break</literal> statement at the end of a case's
- statement list, PHP will go on executing the statements of the
- following case. For example:
+ Only when a <literal>case</literal> statement is found with a value
+ that matches the value of the <literal>switch</literal> expression
+ does PHP begin to execute the statements. PHP continues to execute the
+ statements until the end of the <literal>switch</literal> block,
+ or the first time it sees a <literal>break</literal> statement.
+ If you don't write a <literal>break</literal> statement at the end
+ of a case's statement list, PHP will go on executing the statements
+ of the following case. For example:
<informalexample>
<programlisting>
- /* example 3 */
-
switch ($i) {
case 0:
print "i equals 0";
@@ -530,6 +524,23 @@
it's important not to forget <literal>break</literal> statements
(even though you may want to avoid supplying them on purpose under
certain circumstances).
+
+ <para>
+ The statement list for a case can also be empty, which simply
+ passes control into the statement list for the next case.
+ <informalexample>
+ <programlisting>
+ switch ($i) {
+ case 0:
+ case 1:
+ case 2:
+ print "i is less than 3 but not negative";
+ break;
+ case 3:
+ print "i is 3";
+ }
+ </programlisting>
+ </informalexample>
<para>
A special case is the default case. This case matches anything
@@ -537,8 +548,6 @@
<informalexample>
<programlisting>
- /* example 4 */
-
switch ($i) {
case 0:
print "i equals 0";
@@ -556,10 +565,10 @@
</informalexample>
<para>
- Another fact worth mentioning is that 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.
+ 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.
<sect1 id="function.require">
<title><literal>require</literal></title>
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Jim Winstead: "[PHP-DEV] cvs: /phpdoc/functions dbase.sgml"
- Previous message: Jim Winstead: "[PHP-DEV] cvs: /phpdoc/functions strings.sgml"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

