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

From: Date: Sun, 01 Sep 2002 20:43:43 +0000
Subject: cvs: phpdoc-si /language control-structures.xml
Groups: php.doc.sl 
Request: Send a blank email to doc-sl+get-23@lists.php.net to get a copy of this message
dejan Sun Sep 1 16:43:43 2002 EDT Modified files: /phpdoc-si/language control-structures.xml Log: Enough for tonigh. I'm almost half way through on control.structures Didn't have the time to check for errors. Will do later.

Index: phpdoc-si/language/control-structures.xml diff -u phpdoc-si/language/control-structures.xml:1.1 phpdoc-si/language/control-structures.xml:1.2 --- phpdoc-si/language/control-structures.xml:1.1 Sun Sep 1 10:36:05 2002 +++ phpdoc-si/language/control-structures.xml Sun Sep 1 16:43:42 2002 @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> +<!-- $EN-Revision: 1.63 Maintainer: dejan Status: ready --> <chapter id="control-structures"> <title>Kontrolne strukture</title> @@ -15,56 +16,54 @@ <sect1 id="control-structures.if"> <title><literal>if</literal></title> <para> - The <literal>if</literal> construct is one of the most important - features of many languages, PHP included. It allows for - conditional execution of code fragments. PHP features an - <literal>if</literal> structure that is similar to that of C: + <literal>if</literal> stavek je eden najpomembnej&#353;ih stavkov, + prav tako v PHP-ju. Dovoljuje pogojeno izvajanje kode. PHP ponuja + <literal>if</literal> strukturo podobno tisti v C-ju: <informalexample> <programlisting> <![CDATA[ -if (expr) - statement +if ($izraz) + stavek ]]> </programlisting> </informalexample> </para> <simpara> - As described in <link linkend="language.expressions">the section about - expressions</link>, <replaceable>expr</replaceable> is evaluated to its - Boolean value. If <replaceable>expr</replaceable> evaluates to &true;, - PHP will execute <replaceable>statement</replaceable>, and if it evaluates - to &false; - it'll ignore it. More information about what values evaluate - to &false; can be found in the <link - linkend="language.types.boolean.casting">'Converting to boolean'</link> - section. + Kot opisano v <link linkend="language.expressions">poglavju o izrazih</link>, + je izraz pogojen po njegovi Boolean vrednosti. &#268;e je vrednost <replaceable>izraza</replaceable> + &true;, potem bo PHP izvedel <replaceable>stavek</replaceable>, &#269;e pa bo + &false; - ga bo pa ignoriral. Ve&#269; informacij o tem katere vrednosti se + vrednotijo v &false; lahko najdete v <link + linkend="language.types.boolean.casting">'Converting to boolean'</link> + poglavju. </simpara> <para> - The following example would display <computeroutput>a is bigger - than b</computeroutput> if <replaceable>$a</replaceable> is bigger - than <replaceable>$b</replaceable>: + Naslednji primer bi prikazal <computeroutput>a je ve&#269;ji kot + b</computeroutput>, &#269;e je <replaceable>$a</replaceable> ve&#269;ji + kot <replaceable>$b</replaceable>: <informalexample> <programlisting role="php"> <![CDATA[ if ($a > $b) - print "a is bigger than b"; + print "a je ve&#269;ji kot b"; ]]> </programlisting> </informalexample> </para> <para> - Often you'd want to have more than one statement to be executed - conditionally. Of course, there's no need to wrap each statement - with an <literal>if</literal> clause. Instead, you can group - several statements into a statement group. For example, this code - would display <computeroutput>a is bigger than b</computeroutput> - if <replaceable>$a</replaceable> is bigger than - <replaceable>$b</replaceable>, and would then assign the value of - <replaceable>$a</replaceable> into <replaceable>$b</replaceable>: + Ponavadi bi radi izvedli ve&#269; kot en stavek pogojno. Seveda ni + potrebno vsakega stavka posebej pogojevati z <literal>if</literal> + stavkom. Namesto tega lahko ve&#269; stavkov zdru&#382;ite v + skupino stavkov. Naprimer, ta koda bi prikazala <computeroutput>a + je ve&#269;ji od b</computeroutput>, &#269;e je <replaceable>$a</replaceable> + ce&#269;ji od <replaceable>$b</replaceable>, in bi potem vrednost + spremenljivke <replaceable>$a</replaceable> dodelil spremenljivki + <replaceable>$b</replaceable>: <informalexample> <programlisting role="php"> <![CDATA[ if ($a > $b) { - print "a is bigger than b"; + print "a je ve&#269;ji kot b"; $b = $a; } ]]> @@ -72,43 +71,40 @@ </informalexample> </para> <simpara> - <literal>If</literal> statements can be nested indefinitely within other - <literal>if</literal> statements, which provides you with complete - flexibility for conditional execution of the various parts of your - program. + <literal>If</literal> stavki se lahko neomejeno gnezdijo v druge + <literal>if</literal> stavke, kar vam omogoca popolno kontrolo nad + pogojenim izvajanjem razli&#269;nih delov va&#353;ega programa. </simpara> </sect1> <sect1 id="control-structures.else"> <title><literal>else</literal></title> <para> - Often you'd want to execute a statement if a certain condition is - met, and a different statement if the condition is not met. This - is what <literal>else</literal> is for. <literal>else</literal> - extends an <literal>if</literal> statement to execute a statement - in case the expression in the <literal>if</literal> statement - evaluates to &false;. For example, the following - code would display <computeroutput>a is bigger than - b</computeroutput> if <replaceable>$a</replaceable> is bigger than - <replaceable>$b</replaceable>, and <computeroutput>a is NOT bigger - than b</computeroutput> otherwise: + Ponavadi bi radi izvedli nek stavek, &#269;e je dolo&#269;en + pogoj sprejet in nek drug stavek, &#269;e ta pogoj ni sprejet. + Za to uporabljamo <literal>else</literal> pogojni stavek. <literal>Else</literal> + omogo&#269;a izvajanje nekega stavka, &#269;e <literal>if</literal> + stavek vrne vrednost &false;. Naprimer, spodnja koda bi prikazala + <computeroutput>a je ve&#269;ji kot b</computeroutput>, &3269;e je + <replaceable>$a</replaceable> ve&#269;ji kot <replaceable>$b</replaceable> + in <computeroutput>a NI ve&#269;ji kot b</computeroutput>, &#269;e je + <replaceable>$a</replaceable> manj&#353;i kot <replaceable>$b</replaceable>: <informalexample> <programlisting role="php"> <![CDATA[ if ($a > $b) { - print "a is bigger than b"; + print "a je ve&#269;ji b"; } else { - print "a is NOT bigger than b"; + print "a je manj&#353;i kot b"; } ]]> </programlisting> </informalexample> - The <literal>else</literal> statement is only executed if the - <literal>if</literal> expression evaluated to - &false;, and if there were any - <literal>elseif</literal> expressions - only if they evaluated to - &false; as well (see <link + <literal>Else</literal> stavek se izvede samo &#269;e <literal>if</literal> + stavek vrne vrednost &false; in &#269;e bi imeli kak&#353;ne + <literal>elseif</literal> stavke - prav tako, samo &#269;e bi vrnili vrednost + &false; (poglejte si <link linkend="control-structures.elseif">elseif</link>). </para> @@ -117,155 +113,144 @@ <sect1 id="control-structures.elseif"> <title><literal>elseif</literal></title> <para> - <literal>elseif</literal>, as its name suggests, is a combination - of <literal>if</literal> and <literal>else</literal>. Like - <literal>else</literal>, it extends an <literal>if</literal> - statement to execute a different statement in case the original - <literal>if</literal> expression evaluates to - &false;. However, unlike - <literal>else</literal>, it will execute that alternative - expression only if the <literal>elseif</literal> conditional - expression evaluates to &true;. For example, the - following code would display <computeroutput>a is bigger than - b</computeroutput>, <computeroutput>a equal to b</computeroutput> - or <computeroutput>a is smaller than b</computeroutput>: + <literal>Elseif</literal> je, kot &#382;e njegovo ime ponazarja, + kombinacija <literal>if</literal> in <literal>else</literal> stavka. + Kot <literal>else</literal>, se ta stavek izvede samo &#269;e + <literal>if</literal> stavek vrne vrednost &false;. V nasprotju z + <literal>else</literal>, se bo stavek izvedel samo &#269;e pogojni + stavek vrne &true;. Naprimer, spodnja koda bi prikazala + <computeroutput>a je ve&#269;ji kot b</computeroutput>, + <computeroutput>a je enak b</computeroutput> ali + <computeroutput>a je manj&#353;i kot b</computeroutput>: <informalexample> <programlisting role="php"> <![CDATA[ if ($a > $b) { - print "a is bigger than b"; + print "a je ve&#269;ji kot b"; } elseif ($a == $b) { - print "a is equal to b"; + print "a je enak b"; } else { - print "a is smaller than b"; + print "a je manj&#353;i kot b"; } ]]> </programlisting> </informalexample> </para> <simpara> - There may be several <literal>elseif</literal>s within the same - <literal>if</literal> statement. The first - <literal>elseif</literal> expression (if any) that evaluates to - &true; would be executed. In PHP, you can also - write 'else if' (in two words) and the behavior would be identical - to the one of 'elseif' (in a single word). The syntactic meaning - is slightly different (if you're familiar with C, this is the same - behavior) but the bottom line is that both would result in exactly - the same behavior. + V enem <literal>if</literal> stavku je lahko ve&#269; <literal>elseif</literal> + stavkov. Prvi <literal>elseif</literal> stavek (&#269;e je kak&#353;en), + ki vrne vrednost &true;, bi se izvedel. V PHP-ju lahko napi&#353;ete + 'else if' (dve besedi) in obna&#353;anje bi bilo identi&#269;no stavku + <literal>elseif</literal>. Sintatikti&#269;ni pomen je malo druga&#269;en, + (&#269;e ste seznanjeni z programskim jezikom C, je obna&#353;anje isto) + ampak bistvo je, da bi se oba obna&#353;ala popolnoma enako. </simpara> <simpara> - The <literal>elseif</literal> statement is only executed if the - preceding <literal>if</literal> expression and any preceding - <literal>elseif</literal> expressions evaluated to - &false;, and the current - <literal>elseif</literal> expression evaluated to - &true;. + <literal>Elseif</literal> stavek se izvede samo &#269;e, prej&#353;nji + <literal>if</literal> stavek ali prej&#353;nji <literal>elseif</literal> + stavki, vrnejo vrednost &false; in trenutni <literal>elseif</literal> stavek + vrne vrednost &true;. </simpara> </sect1> <sect1 id="control-structures.alternative-syntax"> - <title>Alternative syntax for control structures</title> + <title>Alternatovna sintaksa za kontrolne strukture</title> <para> - PHP offers an alternative syntax for some of its control - structures; namely, <literal>if</literal>, - <literal>while</literal>, <literal>for</literal>, - <literal>foreach</literal>, and <literal>switch</literal>. - In each case, the basic form of the alternate syntax is to change - the opening brace to a colon (:) and the closing brace to - <literal>endif;</literal>, <literal>endwhile;</literal>, - <literal>endfor;</literal>, <literal>endforeach;</literal>, or - <literal>endswitch;</literal>, respectively. + PHP ponuja alternativno sintakso za nekatere od kontrolnih + struktur; kot so, <literal>if</literal>, <literal>while</literal>, + <literal>for</literal>, <literal>foreach</literal> and + <literal>switch</literal>. V vsakem primeru je osnova + alternativne sintaxe, zamenjava za&#269;etnega oklepaja za + dvopi&#269;je (:) in zaklepaja za <literal>endif;</literal>, + <literal>endwhile;</literal>, <literal>endfor;</literal>, + <literal>endforeach;</literal>. <informalexample> <programlisting role="php"> <![CDATA[ <?php if ($a == 5): ?> -A is equal to 5 +A je enak 5 <?php endif; ?> ]]> </programlisting> </informalexample> </para> <simpara> - In the above example, the HTML block "A is equal to 5" is nested within an - <literal>if</literal> statement written in the alternative syntax. The - HTML block would be displayed only if $a is equal to 5. + V zgornjem primeru je HTML blok ugnezden v <literal>if</literal> stavek + napisan v alternativni sintaksi. HTML blok bi se izpisal samo &#269;e je + $a enak 5. </simpara> <para> - The alternative syntax applies to <literal>else</literal> and - <literal>elseif</literal> as well. The following is an - <literal>if</literal> structure with <literal>elseif</literal> and - <literal>else</literal> in the alternative format: + Alternativna sintaksa se lahko uporablja tudi pri <literal>else</literal> + in <literal>elseif</literal> stavkih. Naslednji primer je <literal>if</literal> + struktura z <literal>elseif</literal> in <literal>else</literal> stavki + napisanimi v alternativni sintaksi: <informalexample> <programlisting role="php"> <![CDATA[ if ($a == 5): - print "a equals 5"; + print "a je enak 5"; print "..."; elseif ($a == 6): - print "a equals 6"; + print "a je enak 6"; print "!!!"; else: - print "a is neither 5 nor 6"; + print "a ni enak 5 niti 6"; endif; ]]> </programlisting> </informalexample> </para> <para> - See also <link linkend="control-structures.while">while</link>, - <link linkend="control-structures.for">for</link>, and <link - linkend="control-structures.if">if</link> for further examples. + Poglejte si tudi <link linkend="control-structures.while">while</link>, + <link linkend="control-structures.for">for</link>, in <link + linkend="control-structures.if">if</link> za dodatne primere. </para> </sect1> <sect1 id="control-structures.while"> <title><literal>while</literal></title> <para> - <literal>while</literal> loops are the simplest type of loop in - PHP. They behave just like their C counterparts. The basic form - of a <literal>while</literal> statement is: + <literal>while</literal> zanke so najenostavnej&#353;e zanke v PHP-ju. + Obna&#353;ajo se ravno tako kot v programskem jeziku C. Osnovna + oblika <literal>while<literal> stavka je: <informalexample> <programlisting> <![CDATA[ -while (expr) statement +while (izraz) stavek ]]> </programlisting> </informalexample> </para> <simpara> - The meaning of a <literal>while</literal> statement is simple. It - tells PHP to execute the nested statement(s) repeatedly, as long - as the <literal>while</literal> expression evaluates to - &true;. The value of the expression is checked - each time at the beginning of the loop, so even if this value - changes during the execution of the nested statement(s), execution - will not stop until the end of the iteration (each time PHP runs - the statements in the loop is one iteration). Sometimes, if the - <literal>while</literal> expression evaluates to - &false; from the very beginning, the nested - statement(s) won't even be run once. + Pomen <literal>while<literal> stavka je enostaven. Uka&#381;e PHP-ju + naj izvaja ugenzden stavek oziroma stavke, dokler <literal>while</literal> + izraz ne vrne vrednosti &true;. Vrednosti izraza je preverjena + vsaki&#269; pred za&#269;etkom zanke, kar pomeni da tudi &#269;e se + vrednosti izraza spremeni med izvajanjem ugnezdenih stavkov, se zanka + ne bo ustavila do konca ponovitve (vsaki&#269; ko PHP izvede ugnezdene + stavke v zanki, se &#353;teje kot eno nadaljevanje). V&#269;asih, &#269;e + <literal>while</literal> izraz vrne vrednost &false; takoj na za&#269;etku, + se ugnezdeni stavki sploh ne bodo izvedli. </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: + Kot pri <literal>if</literal> stavku, lahko tudi tukaj zdru&#381;ite + ve&#269; stavkov v eno <literal>while</literal> zanko, &#269;e jih + zdruzite z zavitimi oklepaji ali z uporabo alternativne sintaxe: <informalexample> <programlisting> <![CDATA[ -while (expr): statement ... endwhile; +while (izraz): stavek ... endwhile; ]]> </programlisting> </informalexample> </para> <para> - The following examples are identical, and both print numbers from - 1 to 10: + Naslednja dva primera sta identi&#269;na in oba bosta izpisala + &#353;tevilke od 1 do 10: <informalexample> <programlisting role="php"> <![CDATA[ -/* example 1 */ +/* primer 1 */ $i = 1; while ($i <= 10) { @@ -274,7 +259,7 @@ (post-increment) */ } -/* example 2 */ +/* primer 2 */ $i = 1; while ($i <= 10): @@ -290,20 +275,20 @@ <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). + <literal>do..while</literal> zanke so zelo podobne + <literal>whilee</literal> zankam, razlika je samo v tem, + da se vrednost izraza preveri na koncu vsakega nadaljevanja in + ne na za&#269;etku. Glavna razlika od navadnih <literal>while</literal> + zank je, da se bo prvo nadaljevanje <literal>do..while</literal> zanke + sigurno izvedel (vrednost izraza se preveri samo na koncu nadaljevanja), + medtem ko se to pri navadni <literal>while</literal> zanki to + nebi zgodilo (vrednost izraza se preveri na za&#269;tku vsakega nadaljevanja in + &#269;e izraz vrne vrednost &false; takoj na za&#269;etku, se zanka + takoj ustavi). + </simpara> <para> - There is just one syntax for <literal>do..while</literal> loops: + Obstaja samo ena sintaksa za <literal>do..while</literal> zanke: <informalexample> <programlisting role="php"> @@ -317,31 +302,36 @@ </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. + Zgornja zanka bi se izvedla samo enkrat, ker pri prvi ponovitvi, + ko se preveri vrednost izraza, izraz vrne &false; + ($i ni ve&269;ji od 0) in zato se zanka ustavi. </simpara> <para> + Izku&#353;eni uporabniki programskega jezika C so verjetno seznanjeni z + razli&#269;nimi na&#269;ini uporabe <literal>do..while</literal> zanke, da + dovoljuje ustavljanje izvajanja v sredini blokov kode, z enkapsulacijo + le-teh v <literal>do..while</literal>(0) in uporabo <link + linkend="control-structures.break"><literal>break</literal></link> + stavka. 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: + statement. Naslednji primer to demonstrira: <informalexample> <programlisting role="php"> <![CDATA[ do { if ($i < 5) { - print "i is not big enough"; + print "i je premajhen"; break; } $i *= $factor; if ($i < $minimum_limit) { break; } - print "i is ok"; + print "i je ok"; ...process i... @@ -351,66 +341,59 @@ </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'. + Ne skrbite, &#269;e tega primera ne razumete takoj. Skripte, prav tako + zahtevne skripte, lahko pi&#353;ete tudi brez uporabe le-tega. </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: + <literal>for</literal> so najbolj zahtevne zanke v PHP-ju. + Obna&#353;ajo se isto kot v C programskem jeziku. Sintaxa + <literal>for</literal> zanke je: <informalexample> <programlisting> <![CDATA[ -for (expr1; expr2; expr3) statement +for (izraz1; izraz2; izraz3) stavek ]]> </programlisting> </informalexample> </para> <simpara> - The first expression (<replaceable>expr1</replaceable>) is - evaluated (executed) once unconditionally at the beginning of the - loop. + Prvi izraz (<replaceable>izraz1</replaceable>) je vedno izveden samo + enkrat - na za&#269;etku zanke. </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. + V za&#269;etku vsakega nadaljevanja, je preverjena vrednost izraza + <replaceable>izraz2</replaceable>. &#268;e je vrednost izraza &true; + se zanka nadaljuje in stavek oziroma stavki se izvedejo. &#268;e je + vrednost izraza &false; se izvajanje zanke kon&269;a. </simpara> <simpara> - At the end of each iteration, <replaceable>expr3</replaceable> is - evaluated (executed). + Na koncu vsakega nadaljevanja se izvede <replaceable>izraz3</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. + Vsak izraz je lahko prazen. &#268;e je <replaceable>Izraz2</replaceable> + prazen, se bo zanka izvajala neskon&#269;no dolgo (PHP ozna&#269;i to kot + &true;, tako kot programski jezik C). To ni tako neuporabno, kot se na + za&#269;etku zdi, ker se velikokrat zgodi, da bi radi zanko izvajali do + pogojnega <link + linkend="control-structures.break"><literal>break</literal></link> + stavka in ne s preverjanjem <literal>for</literal> izraza. </simpara> <para> - Consider the following examples. All of them display numbers from - 1 to 10: + Preu&#269;ite nasledenje primere. Vsi primeri prikazejo stevilke od 1 do 10: <informalexample> <programlisting role="php"> <![CDATA[ -/* example 1 */ +/* primer 1 */ for ($i = 1; $i <= 10; $i++) { print $i; } -/* example 2 */ +/* primer 2 */ for ($i = 1;;$i++) { if ($i > 10) { @@ -419,7 +402,7 @@ print $i; } -/* example 3 */ +/* primer 3 */ $i = 1; for (;;) { @@ -430,7 +413,7 @@ $i++; } -/* example 4 */ +/* primer 4 */ for ($i = 1; $i <= 10; print $i, $i++); ]]> @@ -438,31 +421,30 @@ </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. + Seveda, prvi primer izgleda najbolj spodoben (ali mogoce &#269;etrti), + vendar boste ugotovili, da je mo&#382;nost uporabe praznih izrazov + uporabna v veliko primerih. </simpara> <para> - PHP also supports the alternate "colon syntax" for - <literal>for</literal> loops. + PHP podpira tudi alternativno sintakso za <literal>for</literal> + zanke. <informalexample> <programlisting> <![CDATA[ -for (expr1; expr2; expr3): statement; ...; endfor; +for (izraz1; izraz2; izraz3): stavek; ...; endfor; ]]> </programlisting> </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. + Ostali programski jeziki imajo <literal>foreach</literal> stavek za + sprehod skozi klju&#269;e in vrednosti polja. PHP 3 nima takega stavka; PHP 4 ga ima + (poglejte si <link linkend="control-structures.foreach">foreach</link>). + V PHP 3 si lahko pomagate z <link + linkend="control-structures.while">while</link> zanko v kombinaciji z + <function>list</function> in <function>each</function> funkcijami, s + &#269;imer dose&#382;ete isti efekt. Poglejte si dokumentacijo teh + funkcij za primere. </para> </sect1> @@ -470,64 +452,61 @@ <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. <literal>foreach</literal> works only on arrays, and - will issue an error when you try to use it on a variable with a different - data type or an uninitialized variables. There are two syntaxes; the - second is a minor but useful extension of the first: + PHP 4 (PHP 3 ne) vsebuje <literal>foreach</literal> stavek, tako kot + Perl in nekateri drugi programski jeziki. To vam ponuja enostaven sprehod + cez kjlu&#269;e in vrednosti v polju. <literal>foreach</literal> deluje samo + na poljih in &#269;e jo poskusite uporabiti na spremenljivki drugacnega tipa, + ali na neinicializirani spremenljivki, bo izpisalo napako. Obstajata dve + sintaksi; slednja je manj&#353;a a uporabna raz&#353;iritev prve: <informalexample> <programlisting> <![CDATA[ -foreach(array_expression as $value) statement -foreach(array_expression as $key => $value) statement +foreach(array_expression as $vrednost) stavek +foreach(array_expression as $klju&#269; => $vrednost) stavek ]]> </programlisting> </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). + Prva oblika sintakse se sprehodi preko polja podanega z + <literal>array_expression</literal>. Ob vsaki zanki je vrednost + trenutnega elementa dodeljena spremenljivki <literal>$vrednost</literal> + in interni kazalec na element v polju se poveca za ena + (tako da boste ob naslednji zanki dobili naslednji element v polju). </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. + Druga oblike sintakse naredi isto stvar, le da poleg vrednosti + dobite tudi klju&#269; elementa v polju, katerega vrednost se dodeli + spremenljivki <literal>klju&#269;</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. + Ko se <literal>foreach</literal> prvi&#269; izvede, se interni kazalec + na element v polju nastavi na prvi element v polju. To pomeni, + da vam ni potrebno vsaki&#269; klicati <function>reset</function> + funkcije pred za&#269;etkom <literal>foreach</literal> zanke. </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. + Pomnite tudi, da <literal>foreach</literal> operira na kopiji + podanega polja in ne na polju samem. Kar pomeni, da kazalec na + element v polju ni spremenjen, kot se to zgodi pri <funcition>each</function> + stavku in spremembe v elementu polja ne vplivajo na vrednost originalnega + polja. </para> </note> </para> <note> <para> - <literal>foreach</literal> does not support the ability to - suppress error messages using '@'. + <literal>foreach</literal> ne podpira '@', ki prepre&#269;uje izpis napak. </para> </note> <para> - You may have noticed that the following are functionally - identical: + Verjetno ste opazili, da so naslednji primeri funkcijonalno enaki: <informalexample> <programlisting role="php"> <![CDATA[ @@ -542,7 +521,7 @@ ]]> </programlisting> </informalexample> - The following are also functionally identical: + Tudi naslednji primeri so funkcijonalno enaki: <informalexample> <programlisting role="php"> <![CDATA[ @@ -559,7 +538,7 @@ </informalexample> </para> <para> - Some more examples to demonstrate usages: + &#352;e nekaj primerov uporabe: <informalexample> <programlisting role="php"> <![CDATA[ @@ -622,15 +601,14 @@ <sect1 id="control-structures.break"> <title><literal>break</literal></title> <simpara> - <literal>break</literal> ends execution of the current + <literal>break</literal> kon&#269;a izvajanje <literal>for</literal>, <literal>foreach</literal> <literal>while</literal>, <literal>do..while</literal> or - <literal>switch</literal> structure. + <literal>switch</literal> stavka. </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> sprejme en neobvezen argument, ki pove + koliko ugnezdenih struktur mora kon&#269;ati. </simpara> <para> <informalexample> @@ -668,14 +646,13 @@ <sect1 id="control-structures.continue"> <title><literal>continue</literal></title> <simpara> - <literal>continue</literal> is used within looping structures to - skip the rest of the current loop iteration and continue execution - at the beginning of the next iteration. + <literal>continue</literal> je uporabljen znotraj zank, da prepre&#269;imo + izvajanje preostalega nadaljevanja in pri&#269;nemo na + za&#269;etku naslednjega nadaljevanja zanke. </simpara> <simpara> - <literal>continue</literal> accepts an optional numeric argument - which tells it how many levels of enclosing loops it should skip - to the end of. + <literal>continue</literal> sprejme en neobvezen argument, ki + pove koliko nivojev zakju&#269;enih zank mora spustiti. </simpara> <para> <informalexample> @@ -710,18 +687,17 @@ <sect1 id="control-structures.switch"> <title><literal>switch</literal></title> <simpara> - The <literal>switch</literal> statement is similar to a series of - IF statements on the same expression. In many occasions, you may - want to compare the same variable (or expression) with many - different values, and execute a different piece of code depending - on which value it equals to. This is exactly what the - <literal>switch</literal> statement is for. + <literal>Switch</literal> stavek je podoben seriji IF stavkov na + istem izrazu. V mnogih primerih, bi si &#382;eleli primerjati + vrednost iste spremenljivke in izvajati razli&#269;ne dele kode + glede na vrednost te spremenljivke. Ravno za to uporabljamo + <literal>switch</literal> stavek. </simpara> <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: + Slede&#269;a dva primera prikazujeta dva razli&#269;na na&#269;ina + za doseg istega rezultata. Prvi uporabo serije + <literal>if</literal> stavkov in drugi z uporabo + <literal>switch</literal> stavka: <informalexample> <programlisting role="php"> <![CDATA[ @@ -751,19 +727,17 @@ </informalexample> </para> <para> - It is important to understand how the <literal>switch</literal> - statement is executed in order to avoid mistakes. The - <literal>switch</literal> statement executes line by line - (actually, statement by statement). In the beginning, no code is - executed. Only when a <literal>case</literal> statement is found - with a value that matches the value of the - <literal>switch</literal> expression does PHP begin to execute the - statements. PHP continues to execute the statements until the end - of the <literal>switch</literal> block, or the first time it sees - a <literal>break</literal> statement. If you don't write a - <literal>break</literal> statement at the end of a case's - statement list, PHP will go on executing the statements of the - following case. For example: + Pomembno je razumeti kako se <literal>switch</literal> stavek + izvaja, da se izognete morebitnim napakam. <literal>switch</literal> + izvede vrstico za vrstico (ubistvu, stavek za stavkom). Na + za&#269;etku se ne izvede nobena koda. Koda se izvede &#353;ele, + ko se najde <literal>case</literal> izraz z vrednostjo, ki je enaka + vrednosti <literal>switch</literal> izraza. PHP nadaljuje izvajanje + stavkov do konca <literal>switch</literal> bloka ali do prvega + <literal>break</literal> stavka. &#268;e ne podate + <literal>break</literal> stavka na koncu stavkov <literal>case</literal> + izraza, bo PHP nadaljeval izvajanje stavkov naslednjega + case-a. Primer: <informalexample> <programlisting role="php"> <![CDATA[
« previous php.doc.sl (#23) next »