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

From: Date: Thu, 04 Apr 2002 19:55:40 +0000
Subject: cvs: phpdoc /cs/language control-structures.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969343998@lists.php.net to get a copy of this message
luk Thu Apr 4 14:55:40 2002 EDT Modified files: /phpdoc/cs/language control-structures.xml Log:

Index: phpdoc/cs/language/control-structures.xml diff -u phpdoc/cs/language/control-structures.xml:1.2 phpdoc/cs/language/control-structures.xml:1.3 --- phpdoc/cs/language/control-structures.xml:1.2 Thu Mar 28 18:17:48 2002 +++ phpdoc/cs/language/control-structures.xml Thu Apr 4 14:55:40 2002 @@ -237,10 +237,9 @@ vnoøený kód se neprovede vùbec. </simpara> <para> - Like with the <literal>if</literal> statement, you can group - multiple statements within the same <literal>while</literal> loop - by surrounding a group of statements with curly braces, or by - using the alternate syntax: + Podobnì, jako v pøípadì <literal>if</literal>, mù¾ete i zde seskupovat + konstrukty uvnitø cyklu <literal>while</literal> ohranièením tohoto + kódu slo¾enými závorkami nebo za pou¾ití alternativní syntaxe: <informalexample> <programlisting> <![CDATA[ @@ -250,21 +249,20 @@ </informalexample> </para> <para> - The following examples are identical, and both print numbers from - 1 to 10: + Následující pøíklady jsou identické, oba vypí¹í èísla od 1 do 10: <informalexample> <programlisting role="php"> <![CDATA[ -/* example 1 */ +/* pøíklad 1 */ $i = 1; while ($i <= 10) { - print $i++; /* the printed value would be - $i before the increment - (post-increment) */ + print $i++; /* vyti¹tìná hodnota by byla rovna + $i pøed inkrementací + (post-inkrementace) */ } -/* example 2 */ +/* pøíklad 2 */ $i = 1; while ($i <= 10): @@ -280,20 +278,17 @@ <sect1 id="control-structures.do.while"> <title><literal>do..while</literal></title> <simpara> - <literal>do..while</literal> loops are very similar to - <literal>while</literal> loops, except the truth expression is - checked at the end of each iteration instead of in the beginning. - The main difference from regular <literal>while</literal> loops is - that the first iteration of a <literal>do..while</literal> loop is - guaranteed to run (the truth expression is only checked at the end - of the iteration), whereas it's may not necessarily run with a - regular <literal>while</literal> loop (the truth expression is - checked at the beginning of each iteration, if it evaluates to - &false; right from the beginning, the loop - execution would end immediately). + Cykly <literal>do..while</literal> jsou velmi podobné cyklùm + <literal>while</literal> kromì toho, ¾e pravdivost výrazu se testuje + na konci ka¾dé iterace namísto jejího zaèátku. Hlavní rozdíl oproti + bì¾ným cyklùm <literal>while</literal> je ten, ¾e první iterace cyklu + <literal>do..while</literal> se provede v¾dy (pravdivostní výraz je + testován a¾ na konci iterace), co¾ u cyklu <literal>while</literal> + není zaruèeno (pravdivostní výraz je testován na zaèátku iterace; pokud + je ohodnocen jako &false;, provádìní cyklu hned skonèí). </simpara> <para> - There is just one syntax for <literal>do..while</literal> loops: + Toto je jediná syntaxe pro cykly <literal>do..while</literal>: <informalexample> <programlisting role="php"> @@ -307,33 +302,32 @@ </informalexample> </para> <simpara> - The above loop would run one time exactly, since after the first - iteration, when truth expression is checked, it evaluates to - &false; ($i is not bigger than 0) and the loop - execution ends. + Vý¹e uvedený cyklus by se provedl právì jednou, proto¾e po první iteraci, + kdy¾ se testuje pravdivostní výraz, je tento ohodnocen jako &false; + ($i není vìt¹í ne¾ 0) a provádìní cyklu konèí. </simpara> <para> - 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 - linkend="control-structures.break"><literal>break</literal></link> - statement. The following code fragment demonstrates this: + Pokroèilí programátoøi v C mohou znát i odli¹né pou¾ití cyklu + <literal>do..while</literal>. Kód se uzavøe do + <literal>do..while</literal>(0) a pou¾ije se pøíkaz + <link linkend="control-structures.break"><literal>break</literal></link>. + To umo¾òuje pøeru¹it provádìní cyklu uprostøed kódu, jak je znázornìno + v tomto pøíkladu: <informalexample> <programlisting role="php"> <![CDATA[ do { if ($i < 5) { - print "i is not big enough"; + print "i není dost velké"; break; } $i *= $factor; if ($i < $minimum_limit) { break; } - print "i is ok"; + print "i je ok"; - ...process i... + ...zpracuj i... } while(0); ]]> @@ -341,18 +335,17 @@ </informalexample> </para> <simpara> - Don't worry if you don't understand this right away or at all. - You can code scripts and even powerful scripts without using this - `feature'. + Nedìlejte si nic z toho, ¾e tomu hned a beze zbytku nerozumíte. Mù¾ete + psát skripty, a to i velmi úèinné skripty, i bez pou¾ití této 'finty'. </simpara> </sect1> <sect1 id="control-structures.for"> <title><literal>for</literal></title> <para> - <literal>for</literal> loops are the most complex loops in PHP. - They behave like their C counterparts. The syntax of a - <literal>for</literal> loop is: + Cykly <literal>for</literal> jsou nejslo¾itìj¹ími cykly v PHP. Chovají se + stejnì, jako jejich soukmenovci v C. Syntaxe cyklu <literal>for</literal> + je následující: <informalexample> <programlisting> <![CDATA[ @@ -362,45 +355,41 @@ </informalexample> </para> <simpara> - The first expression (<replaceable>expr1</replaceable>) is - evaluated (executed) once unconditionally at the beginning of the - loop. + První výraz (<replaceable>expr1</replaceable>) je ohodnocen (proveden) + jednou, bezpodmíneènì, na zaèátku cyklu. </simpara> <simpara> - In the beginning of each iteration, - <replaceable>expr2</replaceable> is evaluated. If it evaluates to - &true;, the loop continues and the nested - statement(s) are executed. If it evaluates to - &false;, the execution of the loop ends. + Na zaèátku ka¾dé iterace je ohodnocen výraz + <replaceable>expr2</replaceable>. Pokud má hodnotu &true;, cyklus pokraèuje + a zpracovává se kód uvnitø cyklu. Je-li naopak jeho hodnota &false;, + provádìní cyklu konèí. </simpara> <simpara> - At the end of each iteration, <replaceable>expr3</replaceable> is - evaluated (executed). + Na konci ka¾dé iterace se ohodnotí (provede) výraz + <replaceable>expr3</replaceable>. </simpara> <simpara> - Each of the expressions can be empty. - <replaceable>expr2</replaceable> being empty means the loop should - be run indefinitely (PHP implicitly considers it as - &true;, like C). This may not be as useless as - you might think, since often you'd want to end the loop using a - conditional <link - linkend="control-structures.break"><literal>break</literal></link> - statement instead of using the <literal>for</literal> truth - expression. + Ka¾dý z výrazù mù¾e být prázdný. Prázdný výraz + <replaceable>expr2</replaceable> znamená, ¾e cyklus bude probíhat + nekoneènì dlouho (PHP, stejnì jako C, implicitnì pøedpokládá hodnotu + &true;). To nemusí být tak bez u¾itku, jak si mù¾ete myslet. Èasto mù¾ete + toti¾ chtít ukonèit cyklus pomocí podmínìného pøíkazu + <link linkend="control-structures.break"><literal>break</literal></link>, + namísto pou¾ití pravdivostního výrazu v konstruktu cyklu + <literal>for</literal>. </simpara> <para> - Consider the following examples. All of them display numbers from - 1 to 10: + Pøedpokládejme následující pøíklady. V¹echny zobrazí èísla od 1 do 10: <informalexample> <programlisting role="php"> <![CDATA[ -/* example 1 */ +/* pøíklad 1 */ for ($i = 1; $i <= 10; $i++) { print $i; } -/* example 2 */ +/* pøíklad 2 */ for ($i = 1;;$i++) { if ($i > 10) { @@ -409,7 +398,7 @@ print $i; } -/* example 3 */ +/* pøíklad 3 */ $i = 1; for (;;) { @@ -420,7 +409,7 @@ $i++; } -/* example 4 */ +/* pøíklad 4 */ for ($i = 1; $i <= 10; print $i, $i++); ]]> @@ -428,14 +417,13 @@ </informalexample> </para> <simpara> - Of course, the first example appears to be the nicest one (or - perhaps the fourth), but you may find that being able to use empty - expressions in <literal>for</literal> loops comes in handy in many - occasions. + První pøíklad samozøejmì vypadá nejlépe (nebo mo¾ná i ten ètvrtý), ale + mù¾ete pøijít na to, ¾e schopnost pou¾ívat prázdné výrazy v cyklech + <literal>for</literal> nemusí být nìkdy úplnì k zahození. </simpara> <para> - PHP also supports the alternate "colon syntax" for - <literal>for</literal> loops. + PHP podporuje pro cykly <literal>for</literal> také alternativní + "dvojteèkovou syntaxi". <informalexample> <programlisting> <![CDATA[ @@ -445,14 +433,13 @@ </informalexample> </para> <para> - Other languages have a <literal>foreach</literal> statement to - traverse an array or hash. PHP 3 has no such construct; PHP 4 does - (see <link - linkend="control-structures.foreach">foreach</link>). In PHP 3, you - can combine <link linkend="control-structures.while">while</link> - with the <function>list</function> and <function>each</function> - functions to achieve the same effect. See the documentation for - these functions for an example. + Jiné jazyky mají konstrukt <literal>foreach</literal> k traverzování + polí nebo hashù. V PHP 3 nic takového není, PHP 4 ano (viz <link + linkend="control-structures.foreach">foreach</link>). V PHP 3 mù¾ete + k dosa¾ení stejného efektu kombinovat + <link linkend="control-structures.while">while</link> s funkcemi + <function>list</function> a <function>each</function>. Pøíklady najdete + v dokumentaci. </para> </sect1> @@ -460,10 +447,10 @@ <sect1 id="control-structures.foreach"> <title><literal>foreach</literal></title> <para> - PHP 4 (not PHP 3) includes a <literal>foreach</literal> construct, - much like Perl and some other languages. This simply gives an easy - way to iterate over arrays. There are two syntaxes; the second is - a minor but useful extension of the first: + PHP 4 (ne PHP 3) zahrnuje konstrukt <literal>foreach</literal>, podobnì + jako Perl a rùzné dal¹í jazyky. To poskytuje snadný zpùsob k iteraci + pøes pole. Existují dvì syntaxe; ta druhá je men¹ím, av¹ak u¾iteèným + roz¹íøením té první: <informalexample> <programlisting> <![CDATA[ @@ -474,116 +461,112 @@ </informalexample> </para> <simpara> - The first form loops over the array given by - <literal>array_expression</literal>. On each loop, the value of - the current element is assigned to <literal>$value</literal> and - the internal array pointer is advanced by one (so on the next - loop, you'll be looking at the next element). + První forma traverzuje pole dané výrazem + <literal>array_expression</literal>. V ka¾dé iteraci je hodnota aktuálního + elementu pøiøazena do <literal>$value</literal> a vnitøní ukazatel na pole + je zvý¹en o jednotku (tzn. v pøí¹tí iteraci budete hledìt na následující + element). </simpara> <simpara> - The second form does the same thing, except that the current - element's key will be assigned to the variable - <literal>$key</literal> on each loop. + Druhá forma dìlá toté¾, kromì toho, ¾e aktuální klíè elementu bude + v ka¾dé iteraci pøiøazen do promìnné <literal>$key</literal>. </simpara> <para> <note> <para> - When <literal>foreach</literal> first starts executing, the - internal array pointer is automatically reset to the first element - of the array. This means that you do not need to call - <function>reset</function> before a <literal>foreach</literal> - loop. + Kdy¾ <literal>foreach</literal> zaène provádìní první iterace, + je vnitøní ukazatel automaticky nastaven na první element pole. To + znamená, ¾e pøed <literal>foreach</literal> nemusíte volat + <function>reset</function>. </para> </note> </para> <para> <note> <para> - Also note that <literal>foreach</literal> operates on a copy of - the specified array, not the array itself, therefore the array - pointer is not modified as with the <function>each</function> - construct and changes to the array element returned are not - reflected in the original array. + Uvìdomte si také, ¾e <literal>foreach</literal> pracuje na kopii + specifikovaného pole, nikoli na poli samotném, proto ukazatel na pole + není modifikován tak, jako konstruktem <function>each</function> a + zmìny na vráceném elementu se na pùvodním poli neprojeví. </para> </note> </para> <note> <para> - <literal>foreach</literal> does not support the ability to - suppress error messages using '@'. + <literal>foreach</literal> nepodporuje mo¾nost potlaèit chybová hlá¹ení + pou¾itím '@'. </para> </note> <para> - You may have noticed that the following are functionally - identical: + Mù¾ete si v¹imnout, ¾e následující pøíklady jsou funkènì toto¾né: <informalexample> <programlisting role="php"> <![CDATA[ reset ($arr); while (list(, $value) = each ($arr)) { - echo "Value: $value<br>\n"; + echo "Hodnota: $value<br>\n"; } foreach ($arr as $value) { - echo "Value: $value<br>\n"; + echo "Hodnota: $value<br>\n"; } ]]> </programlisting> </informalexample> - The following are also functionally identical: + Následující pøíklady jsou rovnì¾ funkènì toto¾né: <informalexample> <programlisting role="php"> <![CDATA[ reset ($arr); while (list($key, $value) = each ($arr)) { - echo "Key: $key; Value: $value<br>\n"; + echo "Klíè: $key; Hodnota: $value<br>\n"; } foreach ($arr as $key => $value) { - echo "Key: $key; Value: $value<br>\n"; + echo "Klíè: $key; Hodnota: $value<br>\n"; } ]]> </programlisting> </informalexample> </para> <para> - Some more examples to demonstrate usages: + Dal¹í pøíklady demonstrující pou¾ítí: <informalexample> <programlisting role="php"> <![CDATA[ -/* foreach example 1: value only */ +/* foreach pøíklad 1: pouze hodnota */ $a = array (1, 2, 3, 17); foreach ($a as $v) { - print "Current value of \$a: $v.\n"; + print "Souèasná hodnota \$a: $v.\n"; } -/* foreach example 2: value (with key printed for illustration) */ +/* foreach pøíklad 2: hodnota (pro ilustraci je vypsán i klíè) */ $a = array (1, 2, 3, 17); -$i = 0; /* for illustrative purposes only */ +$i = 0; /* pouze pro ilustrativní úèely */ foreach($a as $v) { print "\$a[$i] => $v.\n"; $i++; } -/* foreach example 3: key and value */ +/* foreach pøíklad 3: klíè a hodnota */ $a = array ( - "one" => 1, - "two" => 2, - "three" => 3, - "seventeen" => 17 + "jedna" => 1, + "dvì" => 2, + "tøi" => 3, + "sedmnáct" => 17 ); foreach($a as $k => $v) { print "\$a[$k] => $v.\n"; } -/* foreach example 4: multi-dimensional arrays */ +/* foreach pøíklad 4: vícerozmìrná pole */ $a[0][0] = "a"; $a[0][1] = "b"; @@ -596,7 +579,7 @@ } } -/* foreach example 5: dynamic arrays */ +/* foreach pøíklad 5: dynamická pole */ foreach(array(1, 2, 3, 4, 5) as $v) { print "$v\n"; @@ -610,39 +593,38 @@ <sect1 id="control-structures.break"> <title><literal>break</literal></title> <simpara> - <literal>break</literal> ends execution of the current + <literal>break</literal> ukonèuje provádìní aktuálního konstruktu <literal>for</literal>, <literal>foreach</literal> - <literal>while</literal>, <literal>do..while</literal> or - <literal>switch</literal> structure. + <literal>while</literal>, <literal>do..while</literal> nebo + <literal>switch</literal>. </simpara> <simpara> - <literal>break</literal> accepts an optional numeric argument - which tells it how many nested enclosing structures are to be - broken out of. + <literal>break</literal> akceptuje nepovinný èíselný argument, který øíká, + z kolika vnoøených struktur se má vyskoèit. </simpara> <para> <informalexample> <programlisting role="php"> <![CDATA[ -$arr = array ('one', 'two', 'three', 'four', 'stop', 'five'); +$arr = array ('jedna', 'dvì', 'tøi', 'ètyøi', 'stop', 'pìt'); while (list (, $val) = each ($arr)) { if ($val == 'stop') { - break; /* You could also write 'break 1;' here. */ + break; /* Tady byste mohli napsat také 'break 1;'. */ } echo "$val<br>\n"; } -/* Using the optional argument. */ +/* Pou¾ití nepovinného argumentu. */ $i = 0; while (++$i) { switch ($i) { case 5: - echo "At 5<br>\n"; - break 1; /* Exit only the switch. */ + echo "Pøi 5<br>\n"; + break 1; /* Ukonèuje pouze switch. */ case 10: - echo "At 10; quitting<br>\n"; - break 2; /* Exit the switch and the while. */ + echo "Pøi 10; konec<br>\n"; + break 2; /* Ukonèuje switch a while. */ default: break; }
« previous php.doc (#969343998) next »