cvs: phpdoc /de/language control-structures.xml

From: Date: Mon, 22 Apr 2002 13:31:06 +0000
Subject: cvs: phpdoc /de/language control-structures.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969344713@lists.php.net to get a copy of this message
betz Mon Apr 22 09:31:06 2002 EDT Modified files: /phpdoc/de/language control-structures.xml Log: CDATA's added, small example correction

Index: phpdoc/de/language/control-structures.xml diff -u phpdoc/de/language/control-structures.xml:1.27 phpdoc/de/language/control-structures.xml:1.28 --- phpdoc/de/language/control-structures.xml:1.27 Sat Apr 13 07:02:54 2002 +++ phpdoc/de/language/control-structures.xml Mon Apr 22 09:31:04 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.27 $ --> +<!-- $Revision: 1.28 $ --> <!-- EN-Revision: 1.22 Maintainer: tzwenny Status: ready --> <chapter id="control-structures"> <title>Kontroll-Strukturen</title> @@ -25,8 +25,10 @@ C-Programmiersprache ist: <informalexample> <programlisting> +<![CDATA[ if (ausdr) Anweisung +]]> </programlisting> </informalexample> </para> @@ -43,8 +45,10 @@ grösser ist als <replaceable>$b</replaceable>: <informalexample> <programlisting role="php"> +<![CDATA[ if ($a > $b) print "a ist grösser als b"; +]]> </programlisting> </informalexample> </para> @@ -61,10 +65,12 @@ gespeichert: <informalexample> <programlisting role="php"> +<![CDATA[ if ($a > $b) { print "a ist grösser als b"; $b = $a; } +]]> </programlisting> </informalexample> </para> @@ -92,11 +98,13 @@ <computeroutput>a ist NICHT grösser als b</computeroutput>: <informalexample> <programlisting role="php"> +<![CDATA[ if ($a > $b) { print "a ist grösser als b"; } else { print "a ist NICHT grösser als b"; } +]]> </programlisting> </informalexample> Die <literal>else</literal>-Anweisung wird nur ausgeführt, wenn @@ -126,6 +134,7 @@ <computeroutput>a ist kleiner als b</computeroutput> ausgeben: <informalexample> <programlisting role="php"> +<![CDATA[ if ($a > $b) { print "a ist grösser als b"; } elseif ($a == $b) { @@ -133,6 +142,7 @@ } else { print "a ist kleiner als b"; } +]]> </programlisting> </informalexample> </para> @@ -168,9 +178,11 @@ bzw. <literal>endswitch;</literal> ersetzt werden. <informalexample> <programlisting role="php"> -&lt;?php if ($a == 5): ?&gt; +<![CDATA[ +<?php if ($a == 5): ?> A ist gleich 5 -&lt;?php endif; ?&gt; +<?php endif; ?> +]]> </programlisting> </informalexample> </para> @@ -186,6 +198,7 @@ und <literal>else</literal> im alternativen Format: <informalexample> <programlisting role="php"> +<![CDATA[ if ($a == 5): print "a ist gleich 5"; print "..."; @@ -195,6 +208,7 @@ else: print "a ist weder 5 noch 6"; endif; +]]> </programlisting> </informalexample> </para> @@ -213,7 +227,9 @@ Grundform einer <literal>while</literal>-Anweisung lautet: <informalexample> <programlisting> +<![CDATA[ while (ausdr) Anweisung +]]> </programlisting> </informalexample> </para> @@ -238,7 +254,9 @@ gebraucht: <informalexample> <programlisting> +<![CDATA[ while (ausdr): Anweisung ... endwhile; +]]> </programlisting> </informalexample> </para> @@ -247,10 +265,11 @@ 1 bis 10 aus: <informalexample> <programlisting> +<![CDATA[ /* Beispiel 1 */ $i = 1; -while ($i &lt;= 10) { +while ($i <= 10) { print $i++; /* es wird erst $i ausgegeben, bevor der Wert erhöht wird (Post-Inkrement) */ @@ -259,10 +278,11 @@ /* Beispiel 2 */ $i = 1; -while ($i &lt;= 10): +while ($i <= 10): print $i; $i++; endwhile; +]]> </programlisting> </informalexample> </para> @@ -285,10 +305,12 @@ Es gibt nur eine Syntax für <literal>do..while</literal>-Schleifen: <informalexample> <programlisting role="php"> +<![CDATA[ $i = 0; do { print $i; } while ($i>0); +]]> </programlisting> </informalexample> </para> @@ -305,13 +327,14 @@ Anweisung zu benutzen. Der folgende Programm-Ausschnitt zeigt dies: <informalexample> <programlisting role="php"> +<![CDATA[ do { - if ($i &lt; 5) { + if ($i < 5) { print "i ist nicht gross genug"; break; } $i *= $factor; - if ($i &lt; $minimum_limit) { + if ($i < $minimum_limit) { break; } print "i ist ok"; @@ -319,6 +342,7 @@ ...bearbeite i... } while(0); +]]> </programlisting> </informalexample> </para> @@ -337,7 +361,9 @@ einer <literal>for</literal>-Schleife sieht so aus: <informalexample> <programlisting> +<![CDATA[ for (ausdr1; ausdr2; ausdr3) Anweisung +]]> </programlisting> </informalexample> </para> @@ -370,16 +396,17 @@ 10 aus: <informalexample> <programlisting role="php"> +<![CDATA[ /* Beispiel 1 */ -for ($i = 1; $i &lt;= 10; $i++) { +for ($i = 1; $i <= 10; $i++) { print $i; } /* Beispiel 2 */ for ($i = 1;;$i++) { - if ($i &gt; 10) { + if ($i > 10) { break; } print $i; @@ -389,7 +416,7 @@ $i = 1; for (;;) { - if ($i &gt; 10) { + if ($i > 10) { break; } print $i; @@ -398,7 +425,8 @@ /* Beispiel 4 */ -for ($i = 1; $i &lt;= 10; print $i, $i++) ; +for ($i = 1; $i <= 10; print $i, $i++) ; +]]> </programlisting> </informalexample> </para> @@ -413,7 +441,9 @@ alternative "Doppelpunkt-Syntax". <informalexample> <programlisting> +<![CDATA[ for (ausdr1; ausdr2; ausdr3): Anweisung; ...; endfor; +]]> </programlisting> </informalexample> </para> @@ -440,8 +470,10 @@ Erweiterung der ersten Syntax: <informalexample> <programlisting> +<![CDATA[ foreach(array_expression as $value) Anweisung foreach(array_expression as $key => $value) Anweisung +]]> </programlisting> </informalexample> </para> @@ -482,27 +514,31 @@ identisch sind: <informalexample> <programlisting role="php"> - reset ($arr); +<![CDATA[ +reset ($arr); while (list(, $value) = each ($arr)) { - echo "Wert: $value&lt;br&gt;\n"; + echo "Wert: $value<br>\n"; } foreach ($arr as $value) { - echo "Wert: $value&lt;br&gt;\n"; + echo "Wert: $value<br>\n"; } +]]> </programlisting> </informalexample> Auch hier funktioniert alles gleich: <informalexample> <programlisting role="php"> +<![CDATA[ reset ($arr); while (list($key, $value) = each ($arr)) { - echo "Schlüssel: $key; Wert: $value&lt;br&gt;\n"; + echo "Schlüssel: $key; Wert: $value<br>\n"; } foreach ($arr as $key => $value) { - echo "Schlüssel: $key; Wert: $value&lt;br&gt;\n"; + echo "Schlüssel: $key; Wert: $value<br>\n"; } +]]> </programlisting> </informalexample> </para> @@ -510,6 +546,7 @@ Noch einige Beispiele, die die Anwendung verdeutlichen: <informalexample> <programlisting role="php"> +<![CDATA[ /* foreach Beispiel 1: Nur der Wert */ $a = array (1, 2, 3, 17); @@ -525,7 +562,7 @@ $i = 0; /* nur für Anschauungs-Zweck */ foreach($a as $v) { - print "\$a[$i] => $k.\n"; + print "\$a[$i] => $v.\n"; $i++; } @@ -541,6 +578,7 @@ foreach($a as $k => $v) { print "\$a[$k] => $v.\n"; } +]]> </programlisting> </informalexample> </para> @@ -562,27 +600,29 @@ <para> <informalexample> <programlisting role="php"> +<![CDATA[ $arr = array ('eins', 'zwei', 'drei', 'stop', 'vier'); while (list ( , $val) = each ($arr)) { if ($val == 'stop') { break; /* Man kann hier auch 'break 1;' schreiben. */ } - echo "$val&lt;br&gt;\n"; + echo "$val<br>\n"; /* Benutzung des optionalen Argumentes. */ $i = 0; while (++$i) { switch ($i) { case 5: - echo "Bei 5&lt;br&gt;\n"; + echo "Bei 5<br>\n"; break 1; /* Beendet nur switch. */ case 10: - echo "Bei 10; quitting&lt;br&gt;\n"; + echo "Bei 10; quitting<br>\n"; break 2; /* Beendet switch und while. */ default: break; } } +]]> </programlisting> </informalexample> </para> @@ -603,6 +643,7 @@ <para> <informalexample> <programlisting role="php"> +<![CDATA[ while (list ($key, $value) = each ($arr)) { if ($key % 2) { // überspringe ungerade Werte continue; @@ -611,18 +652,19 @@ } $i = 0; -while ($i++ &lt; 5) { - echo "Aussen&lt;br&gt;\n"; +while ($i++ < 5) { + echo "Aussen<br>\n"; while (1) { - echo "&nbsp;&nbsp;Mitte&lt;br&gt;\n"; + echo "&nbsp;&nbsp;Mitte<br>\n"; while (1) { - echo "&nbsp;&nbsp;Innen&lt;br&gt;\n"; + echo "&nbsp;&nbsp;Innen<br>\n"; continue 3; } - echo "Das wird nie ausgegeben.&lt;br&gt;\n"; + echo "Das wird nie ausgegeben.<br>\n"; } - echo "Dies auch nicht.&lt;br&gt;\n"; + echo "Dies auch nicht.<br>\n"; } +]]> </programlisting> </informalexample> </para> @@ -644,6 +686,7 @@ das andere eine <literal>switch</literal>-Anweisung: <informalexample> <programlisting role="php"> +<![CDATA[ if ($i == 0) { print "i ist gleich 0"; } @@ -665,6 +708,7 @@ print "i ist gleich 2"; break; } +]]> </programlisting> </informalexample> </para> @@ -684,6 +728,7 @@ Z.B.: <informalexample> <programlisting role="php"> +<![CDATA[ switch ($i) { case 0: print "i ist gleich 0"; @@ -692,6 +737,7 @@ case 2: print "i ist gleich 2"; } +]]> </programlisting> </informalexample> </para> @@ -718,6 +764,7 @@ die Kontrolle einfach an den nächsten case-Teil übergeben. <informalexample> <programlisting role="php"> +<![CDATA[ switch ($i) { case 0: case 1: @@ -727,6 +774,7 @@ case 3: print "i ist gleich 3"; } +]]> </programlisting> </informalexample> </para> @@ -736,6 +784,7 @@ erfasst wurde, wie z.B.: <informalexample> <programlisting role="php"> +<![CDATA[ switch ($i) { case 0: print "i ist gleich 0"; @@ -749,6 +798,7 @@ default: print "i ist weder 0, 1 noch 2"; } +]]> </programlisting> </informalexample> </para> @@ -766,6 +816,7 @@ für Kontroll-Strukturen</link> . <informalexample> <programlisting role="php"> +<![CDATA[ switch ($i): case 0: print "i ist gleich 0"; @@ -779,6 +830,7 @@ default: print "i ist weder 0, 1 noch 2"; endswitch; +]]> </programlisting> </informalexample> </para> @@ -839,7 +891,9 @@ <function>include</function> benutzen. <informalexample> <programlisting role="php"> +<![CDATA[ require ('header.inc'); +]]> </programlisting> </informalexample> </para> @@ -863,6 +917,7 @@ Ergebnisse in das lokale Skript eingebunden werden. <informalexample> <programlisting role="php"> +<![CDATA[ /* Dieses Beispiel geht davon aus, dass ein beliebiger Server zum * Parsen von *.php-Dateien konfiguriert ist. Also meint 'funkt' hier, * dass die Variablen $vareins und $varzwei innerhalb der angeforderten @@ -872,16 +927,17 @@ require ("http://someserver/file.txt?vareins=1&amp;varzwei=2"); /* Funkt. nicht; schaut nach einer lokalen Datei namens -/* 'file.php?varone=1&amp;vartwo=2' */ -require ("file.php?vareins=1&amp;varzwei=2"); +/* 'file.php?varone=1&vartwo=2' */ +require ("file.php?vareins=1&varzwei=2"); /* Funkt. */ -require ("http://someserver/file.php?vareins=1&amp;varzwei=2"); +require ("http://someserver/file.php?vareins=1&varzwei=2"); $vareins = 1; $varzwei = 2; require ("file.txt"); /* Funkt. */ require ("file.php"); /* Funkt. */ +]]> </programlisting> </informalexample> </para> @@ -931,10 +987,12 @@ verwenden, um eine Anzahl unterschiedlicher Dateien einzubinden. <informalexample> <programlisting role="php"> +<![CDATA[ $files = array ('first.inc', 'second.inc', 'third.inc'); for ($i = 0; $i &lt; count($files); $i++) { include $files[$i]; } +]]> </programlisting> </informalexample> </para> @@ -955,6 +1013,7 @@ Anweisungsblock setzen. <informalexample> <programlisting role="php"> +<![CDATA[ /* Das ist falsch und führt nicht zum gewünschten Ergebnis. */ if ($Bedingung) @@ -969,6 +1028,7 @@ } else { include($anderedatei); } +]]> </programlisting> </informalexample> </para> @@ -996,22 +1056,26 @@ <filename>test.inc</filename> im gleichen Verzeichnis wie die Hauptdatei stehen muss: <programlisting role="php"> -&lt;?php -echo "Vor dem Return &lt;br&gt;\n"; +<![CDATA[ +<?php +echo "Vor dem Return <br>\n"; if (1) { return 27; } -echo "Nach dem Return &lt;br&gt;\n"; -?&gt; +echo "Nach dem Return <br>\n"; +?> +]]> </programlisting> </para> <para> Die Datei <filename>main.html</filename> enthält folgendes: <programlisting role="php"> -&lt;?php +<![CDATA[ +<?php $retval = include ('test.inc'); -echo "Datei gibt zurück: '$retval'&lt;br&gt;\n"; -?&gt; +echo "Datei gibt zurück: '$retval'<br>\n"; +?> +]]> </programlisting> </para> <para> @@ -1028,10 +1092,12 @@ Die Datei <filename>main.html</filename> soll nun folgendes enthalten: <programlisting role="php"> -&lt;?php +<![CDATA[ +<?php include ('test.inc'); -echo "Zurück in main.html&lt;br&gt;\n"; -?&gt; +echo "Zurück in main.html<br>\n"; +?> +]]> </programlisting> </para> <para> @@ -1084,25 +1150,27 @@ Ergebnisse in das lokale Skript eingebunden werden. <informalexample> <programlisting role="php"> +<![CDATA[ /* Dieses Beispiel geht davon aus, dass ein beliebiger Server zum * Parsen von *.php-Dateien konfiguriert ist. Also meint 'funkt' hier, * dass die Variablen $vareins und $varzwei innerhalb der angeforderten * Datei vorhanden sind. */ /* Funkt. nicht; file.txt wird vom besagten Server nicht geparst. */ -include ("http://someserver/file.txt?vareins=1&amp;varzwei=2"); +include ("http://someserver/file.txt?vareins=1&varzwei=2"); /* Funkt. nicht; schaut nach einer lokalen Datei namens -/* 'file.php?varone=1&amp;vartwo=2' */ -include ("file.php?vareins=1&amp;varzwei=2"); +/* 'file.php?varone=1&vartwo=2' */ +include ("file.php?vareins=1&varzwei=2"); /* Funkt. */ -include ("http://someserver/file.php?vareins=1&amp;varzwei=2"); +include ("http://someserver/file.php?vareins=1&varzwei=2"); $vareins = 1; $varzwei = 2; include ("file.txt"); /* Funkt. */ include ("file.php"); /* Funkt. */ +]]> </programlisting> </informalexample> </para> @@ -1136,19 +1204,22 @@ <example> <title>utils.inc</title> <programlisting role="php"> -&lt;?php +<![CDATA[ +<?php define(PHPVERSION, floor(phpversion())); echo "GLOBALE SIND GUT\n"; function guterTee() { return "Oolong-Tee schmeckt gut!"; } -?&gt; +?> +]]> </programlisting> </example> <example> <title>foolib.inc</title> <programlisting role="php"> -&lt;?php +<![CDATA[ +<?php require ("utils.inc"); function zeigeVar($var) { if (PHPVERSION == 4) { @@ -1159,7 +1230,8 @@ } // es folgen weiter Funktionen ... -?&gt; +?> +]]> </programlisting> </example> Nun schreiben Sie ein Skript @@ -1167,7 +1239,8 @@ <example> <title>cause_error_require.php</title> <programlisting role="php"> -&lt;?php +<![CDATA[ +<?php require("foolib.inc"); /* das Folgende erzeugt einen Fehler */ require("utils.inc"); @@ -1177,17 +1250,21 @@ echo "Aufruf von guterTee: ".guterTee()."\n"; echo "Ausgabe foo: \n"; showVar($foo); -?&gt; +?> +]]> </programlisting> </example> Wenn Sie letzteres starten, wird folgende Ausgabe erzeugt (gilt für PHP 4.01pl2): <informalexample> <programlisting> +<![CDATA[ GLOBALE SIND GUT GLOBALE SIND GUT Fatal error: Cannot redeclare causeerror() in utils.inc on line 5 + +]]> </programlisting> </informalexample> Durch Umschreiben von <literal>foolib.inc</literal> und @@ -1198,26 +1275,31 @@ <example> <title>foolib.inc (fixed)</title> <programlisting role="php"> +<![CDATA[ ... require_once("utils.inc"); function showVar($var) { ... +]]> </programlisting> </example> <example> <title>avoid_error_require_once.php</title> <programlisting role="php"> +<![CDATA[ ... require_once("foolib.inc"); require_once("utils.inc"); $foo = array("1",array("complex","quaternion")); ... +]]> </programlisting> </example> Beim nachfolgenden Aufruf wird folgende Ausgabe erzeugt (bei PHP 4.0.1pl2): <informalexample> <programlisting> +<![CDATA[ GLOBALE SIND GUT dies erfordert utils.inc, das auch in foolib.inc erforderlich ist @@ -1225,14 +1307,15 @@ Ausgabe foo: Array ( - [0] =&gt; 1 - [1] =&gt; Array + [0] => 1 + [1] => Array ( - [0] =&gt; complex - [1] =&gt; quaternion + [0] => complex + [1] => quaternion ) ) +]]> </programlisting> </informalexample> </para>
« previous php.doc (#969344713) next »