cvs: phpdoc /en/language control-structures.xml
| From: | Friedhelm Betz | Date: | Sat, 17 Jan 2004 20:22:45 +0000 |
| Subject: | cvs: phpdoc /en/language control-structures.xml | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969358264@lists.php.net to get a copy of this message | ||
betz Sat Jan 17 15:22:45 2004 EDT
Modified files:
/phpdoc/en/language control-structures.xml
Log:
cs: indenting, use echo for output
Index: phpdoc/en/language/control-structures.xml diff -u phpdoc/en/language/control-structures.xml:1.84 phpdoc/en/language/control-structures.xml:1.85 --- phpdoc/en/language/control-structures.xml:1.84 Tue Jan 6 04:20:49 2004 +++ phpdoc/en/language/control-structures.xml Sat Jan 17 15:22:45 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.84 $ --> +<!-- $Revision: 1.85 $ --> <chapter id="control-structures"> <title>Control Structures</title> @@ -49,7 +49,7 @@ <![CDATA[ <?php if ($a > $b) - print "a is bigger than b"; + echo "a is bigger than b"; ?> ]]> </programlisting> @@ -69,7 +69,7 @@ <![CDATA[ <?php if ($a > $b) { - print "a is bigger than b"; + echo "a is bigger than b"; $b = $a; } ?> @@ -103,9 +103,9 @@ <![CDATA[ <?php if ($a > $b) { - print "a is bigger than b"; + echo "a is bigger than b"; } else { - print "a is NOT bigger than b"; + echo "a is NOT bigger than b"; } ?> ]]> @@ -142,11 +142,11 @@ <![CDATA[ <?php if ($a > $b) { - print "a is bigger than b"; + echo "a is bigger than b"; } elseif ($a == $b) { - print "a is equal to b"; + echo "a is equal to b"; } else { - print "a is smaller than b"; + echo "a is smaller than b"; } ?> ]]> @@ -211,13 +211,13 @@ <![CDATA[ <?php if ($a == 5): - print "a equals 5"; - print "..."; + echo "a equals 5"; + echo "..."; elseif ($a == 6): - print "a equals 6"; - print "!!!"; + echo "a equals 6"; + echo "!!!"; else: - print "a is neither 5 nor 6"; + echo "a is neither 5 nor 6"; endif; ?> ]]> @@ -282,7 +282,7 @@ $i = 1; while ($i <= 10) { - print $i++; /* the printed value would be + echo $i++; /* the printed value would be $i before the increment (post-increment) */ } @@ -291,7 +291,7 @@ $i = 1; while ($i <= 10): - print $i; + echo $i; $i++; endwhile; ?> @@ -325,7 +325,7 @@ <?php $i = 0; do { - print $i; + echo $i; } while ($i > 0); ?> ]]> @@ -342,7 +342,7 @@ Advanced C users may be familiar with a different usage of the <literal>do..while</literal> loop, to allow stopping execution in the middle of code blocks, by encapsulating them with - <literal>do..while</literal>(0), and using the <link + <literal>do..while</literal> (0), and using the <link linkend="control-structures.break"><literal>break</literal></link> statement. The following code fragment demonstrates this: <informalexample> @@ -351,18 +351,18 @@ <?php do { if ($i < 5) { - print "i is not big enough"; + echo "i is not big enough"; break; } $i *= $factor; if ($i < $minimum_limit) { break; } - print "i is ok"; + echo "i is ok"; /* process i */ -} while(0); +} while (0); ?> ]]> </programlisting> @@ -426,7 +426,7 @@ /* example 1 */ for ($i = 1; $i <= 10; $i++) { - print $i; + echo $i; } /* example 2 */ @@ -435,23 +435,23 @@ if ($i > 10) { break; } - print $i; + echo $i; } /* example 3 */ $i = 1; -for (;;) { +for (; ; ) { if ($i > 10) { break; } - print $i; + echo $i; $i++; } /* example 4 */ -for ($i = 1; $i <= 10; print $i, $i++); +for ($i = 1; $i <= 10; echo $i, $i++); ?> ]]> </programlisting> @@ -576,7 +576,8 @@ <programlisting role="php"> <![CDATA[ <?php -reset ($arr); +$arr = array("one", "two", "three"); +reset($arr); while (list($key, $value) = each ($arr)) { echo "Key: $key; Value: $value<br />\n"; } @@ -597,26 +598,26 @@ <?php /* foreach example 1: value only */ -$a = array (1, 2, 3, 17); +$a = array(1, 2, 3, 17); foreach ($a as $v) { - print "Current value of \$a: $v.\n"; + echo "Current value of \$a: $v.\n"; } /* foreach example 2: value (with key printed for illustration) */ -$a = array (1, 2, 3, 17); +$a = array(1, 2, 3, 17); $i = 0; /* for illustrative purposes only */ foreach ($a as $v) { - print "\$a[$i] => $v.\n"; + echo "\$a[$i] => $v.\n"; $i++; } /* foreach example 3: key and value */ -$a = array ( +$a = array( "one" => 1, "two" => 2, "three" => 3, @@ -624,7 +625,7 @@ ); foreach ($a as $k => $v) { - print "\$a[$k] => $v.\n"; + echo "\$a[$k] => $v.\n"; } /* foreach example 4: multi-dimensional arrays */ @@ -636,14 +637,14 @@ foreach ($a as $v1) { foreach ($v1 as $v2) { - print "$v2\n"; + echo "$v2\n"; } } /* foreach example 5: dynamic arrays */ foreach (array(1, 2, 3, 4, 5) as $v) { - print "$v\n"; + echo "$v\n"; } ?> ]]> @@ -670,7 +671,7 @@ <programlisting role="php"> <![CDATA[ <?php -$arr = array ('one', 'two', 'three', 'four', 'stop', 'five'); +$arr = array('one', 'two', 'three', 'four', 'stop', 'five'); while (list (, $val) = each ($arr)) { if ($val == 'stop') { break; /* You could also write 'break 1;' here. */ @@ -816,31 +817,31 @@ </note> <para> The following two examples are two different ways to write the - same thing, one using a series of <literal>if</literal> - statements, and the other using the <literal>switch</literal> - statement: + same thing, one using a series of <literal>if</literal> and + <literal>elseif</literal> statements, and the other using the + <literal>switch</literal> statement: <informalexample> <programlisting role="php"> <![CDATA[ <?php if ($i == 0) { - print "i equals 0"; + echo "i equals 0"; } elseif ($i == 1) { - print "i equals 1"; + echo "i equals 1"; } elseif ($i == 2) { - print "i equals 2"; + echo "i equals 2"; } switch ($i) { - case 0: - print "i equals 0"; - break; - case 1: - print "i equals 1"; - break; - case 2: - print "i equals 2"; - break; +case 0: + echo "i equals 0"; + break; +case 1: + echo "i equals 1"; + break; +case 2: + echo "i equals 2"; + break; } ?> ]]> @@ -866,12 +867,12 @@ <![CDATA[ <?php switch ($i) { - case 0: - print "i equals 0"; - case 1: - print "i equals 1"; - case 2: - print "i equals 2"; +case 0: + echo "i equals 0"; +case 1: + echo "i equals 1"; +case 2: + echo "i equals 2"; } ?> ]]> @@ -879,9 +880,9 @@ </informalexample> </para> <simpara> - Here, if $i is equal to 0, PHP would execute all of the print + Here, if $i is equal to 0, PHP would execute all of the echo statements! If $i is equal to 1, PHP would execute the last two - print statements. You would get the expected behavior ('i equals 2' + echo statements. You would get the expected behavior ('i equals 2' would be displayed) only if $i is equal to 2. Thus, it is important not to forget <literal>break</literal> statements (even though you may want to avoid supplying them on purpose under @@ -903,13 +904,13 @@ <![CDATA[ <?php switch ($i) { - case 0: - case 1: - case 2: - print "i is less than 3 but not negative"; - break; - case 3: - print "i is 3"; +case 0: +case 1: +case 2: + echo "i is less than 3 but not negative"; + break; +case 3: + echo "i is 3"; } ?> ]]> @@ -925,17 +926,17 @@ <![CDATA[ <?php 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"; +case 0: + echo "i equals 0"; + break; +case 1: + echo "i equals 1"; + break; +case 2: + echo "i equals 2"; + break; +default: + echo "i is not equal to 0, 1 or 2"; } ?> ]]> @@ -958,17 +959,17 @@ <![CDATA[ <?php 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"; +case 0: + echo "i equals 0"; + break; +case 1: + echo "i equals 1"; + break; +case 2: + echo "i equals 2"; + break; +default: + echo "i is not equal to 0, 1 or 2"; endswitch; ?> ]]> @@ -1054,7 +1055,7 @@ <![CDATA[ <?php // A function that records the time when it is called -function profile ($dump = FALSE) +function profile($dump = FALSE) { static $profile; @@ -1072,17 +1073,17 @@ register_tick_function("profile"); // Initialize the function before the declare block -profile (); +profile(); // Run a block of code, throw a tick every 2nd statement -declare (ticks=2) { +declare(ticks=2) { for ($x = 1; $x < 50; ++$x) { - echo similar_text (md5($x), md5($x*$x)), "<br />;"; + echo similar_text(md5($x), md5($x*$x)), "<br />;"; } } // Display the data stored in the profiler -print_r (profile (TRUE)); +print_r(profile (TRUE)); ?> ]]> </programlisting>
Index: phpdoc/en/language/control-structures.xml diff -u phpdoc/en/language/control-structures.xml:1.84 phpdoc/en/language/control-structures.xml:1.85 --- phpdoc/en/language/control-structures.xml:1.84 Tue Jan 6 04:20:49 2004 +++ phpdoc/en/language/control-structures.xml Sat Jan 17 15:22:45 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.84 $ --> +<!-- $Revision: 1.85 $ --> <chapter id="control-structures"> <title>Control Structures</title> @@ -49,7 +49,7 @@ <![CDATA[ <?php if ($a > $b) - print "a is bigger than b"; + echo "a is bigger than b"; ?> ]]> </programlisting> @@ -69,7 +69,7 @@ <![CDATA[ <?php if ($a > $b) { - print "a is bigger than b"; + echo "a is bigger than b"; $b = $a; } ?> @@ -103,9 +103,9 @@ <![CDATA[ <?php if ($a > $b) { - print "a is bigger than b"; + echo "a is bigger than b"; } else { - print "a is NOT bigger than b"; + echo "a is NOT bigger than b"; } ?> ]]> @@ -142,11 +142,11 @@ <![CDATA[ <?php if ($a > $b) { - print "a is bigger than b"; + echo "a is bigger than b"; } elseif ($a == $b) { - print "a is equal to b"; + echo "a is equal to b"; } else { - print "a is smaller than b"; + echo "a is smaller than b"; } ?> ]]> @@ -211,13 +211,13 @@ <![CDATA[ <?php if ($a == 5): - print "a equals 5"; - print "..."; + echo "a equals 5"; + echo "..."; elseif ($a == 6): - print "a equals 6"; - print "!!!"; + echo "a equals 6"; + echo "!!!"; else: - print "a is neither 5 nor 6"; + echo "a is neither 5 nor 6"; endif; ?> ]]> @@ -282,7 +282,7 @@ $i = 1; while ($i <= 10) { - print $i++; /* the printed value would be + echo $i++; /* the printed value would be $i before the increment (post-increment) */ } @@ -291,7 +291,7 @@ $i = 1; while ($i <= 10): - print $i; + echo $i; $i++; endwhile; ?> @@ -325,7 +325,7 @@ <?php $i = 0; do { - print $i; + echo $i; } while ($i > 0); ?> ]]> @@ -342,7 +342,7 @@ Advanced C users may be familiar with a different usage of the <literal>do..while</literal> loop, to allow stopping execution in the middle of code blocks, by encapsulating them with - <literal>do..while</literal>(0), and using the <link + <literal>do..while</literal> (0), and using the <link linkend="control-structures.break"><literal>break</literal></link> statement. The following code fragment demonstrates this: <informalexample> @@ -351,18 +351,18 @@ <?php do { if ($i < 5) { - print "i is not big enough"; + echo "i is not big enough"; break; } $i *= $factor; if ($i < $minimum_limit) { break; } - print "i is ok"; + echo "i is ok"; /* process i */ -} while(0); +} while (0); ?> ]]> </programlisting> @@ -426,7 +426,7 @@ /* example 1 */ for ($i = 1; $i <= 10; $i++) { - print $i; + echo $i; } /* example 2 */ @@ -435,23 +435,23 @@ if ($i > 10) { break; } - print $i; + echo $i; } /* example 3 */ $i = 1; -for (;;) { +for (; ; ) { if ($i > 10) { break; } - print $i; + echo $i; $i++; } /* example 4 */ -for ($i = 1; $i <= 10; print $i, $i++); +for ($i = 1; $i <= 10; echo $i, $i++); ?> ]]> </programlisting> @@ -576,7 +576,8 @@ <programlisting role="php"> <![CDATA[ <?php -reset ($arr); +$arr = array("one", "two", "three"); +reset($arr); while (list($key, $value) = each ($arr)) { echo "Key: $key; Value: $value<br />\n"; } @@ -597,26 +598,26 @@ <?php /* foreach example 1: value only */ -$a = array (1, 2, 3, 17); +$a = array(1, 2, 3, 17); foreach ($a as $v) { - print "Current value of \$a: $v.\n"; + echo "Current value of \$a: $v.\n"; } /* foreach example 2: value (with key printed for illustration) */ -$a = array (1, 2, 3, 17); +$a = array(1, 2, 3, 17); $i = 0; /* for illustrative purposes only */ foreach ($a as $v) { - print "\$a[$i] => $v.\n"; + echo "\$a[$i] => $v.\n"; $i++; } /* foreach example 3: key and value */ -$a = array ( +$a = array( "one" => 1, "two" => 2, "three" => 3, @@ -624,7 +625,7 @@ ); foreach ($a as $k => $v) { - print "\$a[$k] => $v.\n"; + echo "\$a[$k] => $v.\n"; } /* foreach example 4: multi-dimensional arrays */ @@ -636,14 +637,14 @@ foreach ($a as $v1) { foreach ($v1 as $v2) { - print "$v2\n"; + echo "$v2\n"; } } /* foreach example 5: dynamic arrays */ foreach (array(1, 2, 3, 4, 5) as $v) { - print "$v\n"; + echo "$v\n"; } ?> ]]> @@ -670,7 +671,7 @@ <programlisting role="php"> <![CDATA[ <?php -$arr = array ('one', 'two', 'three', 'four', 'stop', 'five'); +$arr = array('one', 'two', 'three', 'four', 'stop', 'five'); while (list (, $val) = each ($arr)) { if ($val == 'stop') { break; /* You could also write 'break 1;' here. */ @@ -816,31 +817,31 @@ </note> <para> The following two examples are two different ways to write the - same thing, one using a series of <literal>if</literal> - statements, and the other using the <literal>switch</literal> - statement: + same thing, one using a series of <literal>if</literal> and + <literal>elseif</literal> statements, and the other using the + <literal>switch</literal> statement: <informalexample> <programlisting role="php"> <![CDATA[ <?php if ($i == 0) { - print "i equals 0"; + echo "i equals 0"; } elseif ($i == 1) { - print "i equals 1"; + echo "i equals 1"; } elseif ($i == 2) { - print "i equals 2"; + echo "i equals 2"; } switch ($i) { - case 0: - print "i equals 0"; - break; - case 1: - print "i equals 1"; - break; - case 2: - print "i equals 2"; - break; +case 0: + echo "i equals 0"; + break; +case 1: + echo "i equals 1"; + break; +case 2: + echo "i equals 2"; + break; } ?> ]]> @@ -866,12 +867,12 @@ <![CDATA[ <?php switch ($i) { - case 0: - print "i equals 0"; - case 1: - print "i equals 1"; - case 2: - print "i equals 2"; +case 0: + echo "i equals 0"; +case 1: + echo "i equals 1"; +case 2: + echo "i equals 2"; } ?> ]]> @@ -879,9 +880,9 @@ </informalexample> </para> <simpara> - Here, if $i is equal to 0, PHP would execute all of the print + Here, if $i is equal to 0, PHP would execute all of the echo statements! If $i is equal to 1, PHP would execute the last two - print statements. You would get the expected behavior ('i equals 2' + echo statements. You would get the expected behavior ('i equals 2' would be displayed) only if $i is equal to 2. Thus, it is important not to forget <literal>break</literal> statements (even though you may want to avoid supplying them on purpose under @@ -903,13 +904,13 @@ <![CDATA[ <?php switch ($i) { - case 0: - case 1: - case 2: - print "i is less than 3 but not negative"; - break; - case 3: - print "i is 3"; +case 0: +case 1: +case 2: + echo "i is less than 3 but not negative"; + break; +case 3: + echo "i is 3"; } ?> ]]> @@ -925,17 +926,17 @@ <![CDATA[ <?php 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"; +case 0: + echo "i equals 0"; + break; +case 1: + echo "i equals 1"; + break; +case 2: + echo "i equals 2"; + break; +default: + echo "i is not equal to 0, 1 or 2"; } ?> ]]> @@ -958,17 +959,17 @@ <![CDATA[ <?php 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"; +case 0: + echo "i equals 0"; + break; +case 1: + echo "i equals 1"; + break; +case 2: + echo "i equals 2"; + break; +default: + echo "i is not equal to 0, 1 or 2"; endswitch; ?> ]]> @@ -1054,7 +1055,7 @@ <![CDATA[ <?php // A function that records the time when it is called -function profile ($dump = FALSE) +function profile($dump = FALSE) { static $profile; @@ -1072,17 +1073,17 @@ register_tick_function("profile"); // Initialize the function before the declare block -profile (); +profile(); // Run a block of code, throw a tick every 2nd statement -declare (ticks=2) { +declare(ticks=2) { for ($x = 1; $x < 50; ++$x) { - echo similar_text (md5($x), md5($x*$x)), "<br />;"; + echo similar_text(md5($x), md5($x*$x)), "<br />;"; } } // Display the data stored in the profiler -print_r (profile (TRUE)); +print_r(profile (TRUE)); ?> ]]> </programlisting>