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