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; }