cvs: /phpdoc/language control-structures.sgml

From: Date: Sun, 01 Aug 1999 00:46:16 +0000
Subject: cvs: /phpdoc/language control-structures.sgml
Groups: php.dev 
Request: Send a blank email to php-dev+get-9415@lists.php.net to get a copy of this message
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>

« previous php.dev (#9415) next »